Reputation: 11882
I want use grrovy constant from Shared Libray in my Jenkins pipeline. I try this but I have this error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 27: Not a valid stage section definition: "def paramChecker = ParameterChecker.new(this)". Some extra configuration is required. @ line 27, column 9. stage('Checkout') {
def libIdentifier = "project-jenkins-pipeline"
def libGitBranch = params.LIB_GIT_BRANCH
if(libGitBranch) {
libIdentifier += "@${libGitBranch}"
}
def com = library(identifier: libIdentifier, changelog: false).com
def Constants = com.project.Constants
def ParameterChecker = com.project.ParameterChecker
pipeline {
agent {
docker {
label "linux"
image "my-host:8082/project-build-java:jdk1.6-jdk1.8-mvn3.2.5"
registryUrl 'http://my-host:8082'
registryCredentialsId 'ReadNexusAccountService'
}
}
stages {
stage('Clean workspace') {
steps {
deleteDir()
}
}
stage('Checkout') {
def paramChecker = ParameterChecker.new(this)
paramChecker.checkProjectAndBranchNames()
checkoutGitSCM(
url: "${Constants.BITBUCKET_URL}/${paramChecker.projectName}.git",
tag: Constants.GIT_PROJECT_DEFAULT_BRANCH
)
}
stage('Compilation Maven') {
steps {
timestamps {
sh 'mvn -version'
}
}
}
}
}
Upvotes: 0
Views: 845
Reputation: 11882
I had script
in steps
in stage('Checkout')
def libIdentifier = "project-jenkins-pipeline"
def libGitBranch = params.LIB_GIT_BRANCH
if(libGitBranch) {
libIdentifier += "@${libGitBranch}"
}
def com = library(identifier: libIdentifier, changelog: false).com
pipeline {
agent {
docker {
label "linux"
image "my-host:8082/project-build-java:jdk1.6-jdk1.8-mvn3.2.5"
registryUrl 'http://my-host:8082'
registryCredentialsId 'ReadNexusAccountService'
}
}
stages {
stage('Clean workspace') {
steps {
deleteDir()
}
}
stage('Checkout') {
steps {
script {
def Constants = com.project.Constants
def ParameterChecker = com.project.ParameterChecker
def paramChecker = ParameterChecker.new(this)
paramChecker.checkProjectAndBranchNames()
checkoutGitSCM(
url: "${Constants.BITBUCKET_URL}/${paramChecker.projectName}.git",
tag: Constants.GIT_PROJECT_DEFAULT_BRANCH
)
}
}
}
stage('Compilation Maven') {
steps {
timestamps {
sh 'mvn -version'
}
}
}
}
}
Thanks at @Matt Schuchard and Jenkins: Cannot define variable in pipeline stage
Upvotes: 0