如何从服务设置 jenkins 描述性管道的 BuildNumber?
How to set the BuildNumber of a jenkins descriptive pipeline from a service?
我已尝试完成此操作: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 描述性管道文件的等效项是什么?
你必须用 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}"
}
}
//...
}
//...
我已尝试完成此操作: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 描述性管道文件的等效项是什么?
你必须用 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}"
}
}
//...
}
//...