I am migrating jenkins-workflow job to new template based workflow job. Because the build number is used as part of the version of build artifacts the workflow produces I have
Unfortunately the methods listed above didn't work for me when using folders. I resorted to the following in the Jenkins script console:
job = Jenkins.getInstance().getItemByFullName("BSKAzureConversion-Jobs/master", Job.class)
job.nextBuildNumber = 92
job.save()
Try running below script in Jenkins Script Console.. Change "workFlow" to your Jobname
def job = Jenkins.instance.getItem("workFlow")
job.nextBuildNumber = 10
job.saveNextBuildNumber()
I also found another way of doing this by using 'jenkins-cli'. It works for locked down installations where access to script console is not available (Cloudbees Enterprise Jenkins)
java -jar jenkins-cli.jar -s https://instanceURL/ \
set-next-build-number workflow-name 33
A few notes:
@NonCPS
Jenkins.instance
are not accessible otherwiseJenkins.instance.getItem()
won't work well with folders. Use Jenkins.instance.getItemByFullName
against the env.JOB_NAME
job.nextBuildNumber
will take effect subsequent build, so go ahead and kick off the next oneCode:
@NonCPS
def updateBuildNumber(build_number) {
def job = Jenkins.instance.getItemByFullName(env.JOB_NAME, Job.class)
job.nextBuildNumber = build_number
job.saveNextBuildNumber()
build env.JOB_NAME
return true
}
Or, you could add a snippet like this to your Pipeline/Workflow job DSL script (aka Jenkinsfile):
offset = 5
currentBuild.displayName = "#" + (currentBuild.number + offset)