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
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
}