我尝试完成以下操作:https://www.quernus.co.uk/2016/08/12/global-build-numbers-in-jenkins-multibranch-pipeline-builds/,以便在所有分支上都具有唯一的内部版本号。
//...
stages {
stage('Initialization started'){
steps{
env.BUILD_ID = 'http://Energy-JobSrv2.vm.dom/api/buildnumber'.ToURL().text
currentBuild.displayName = "#" + env.BUILD_ID
echo "Job parameters:\n\t- ROOT_FOLDER: ${params.ROOT_FOLDER}\n\t- Build X86: ${params.buildX86}\n\t- Build X64: ${params.buildX64}\n\t- Commit Version changes: ${params.commitVersionChanges}\n\t- Setup Version: ${params.version}.${env.BUILD_NUMBER}\n\t- Setup Configuration: ${params.setupConfiguration}\nCurrent repository: ${workspace}"
}
}
//...
}
//...
但是我认为Jenkins描述性管道文件还没有完成,因为当我尝试运行它时,我得到了:
[Bitbucket] Build result notified
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 17: Expected a step @ line 17, column 5.
env.BUILD_ID = 'http://Energy-JobSrv2.vm.dom/api/buildnumber'.ToURL().text
^
WorkflowScript: 18: Expected a step @ line 18, column 5.
currentBuild.displayName = "#" + env.BUILD_ID
Jenkins描述性管道文件等效于什么?
答案 0 :(得分:2)
您必须使用script
封装命令:
//...
stages {
stage('Initialization started'){
steps{
script{
env.BUILD_ID = 'http://Energy-JobSrv2.vm.dom/api/buildnumber'.ToURL().text
currentBuild.displayName = "#" + env.BUILD_ID
}
echo "Job parameters:\n\t- ROOT_FOLDER: ${params.ROOT_FOLDER}\n\t- Build X86: ${params.buildX86}\n\t- Build X64: ${params.buildX64}\n\t- Commit Version changes: ${params.commitVersionChanges}\n\t- Setup Version: ${params.version}.${env.BUILD_NUMBER}\n\t- Setup Configuration: ${params.setupConfiguration}\nCurrent repository: ${workspace}"
}
}
//...
}
//...