Builds from second job should have BUILD_NUMBER larger by one than newest build from first job, and when second job triggered third job then he should have the same BUILD_NUMBER as second. When third job will be triggered manual, then he also should have BUILD_NUMBER larger by one than newest build from first job.
I hope that what I wrote is understandable ;P
I wrote script in groovy:
import jenkins.model.*
// Access to the Jenkins instance
jenkinsInstance = jenkins.model.Jenkins.instance
// Select jobs that match.
searchedJobName = "^synchronize_build_numbers.*"
jobName = "synchronize_build_numbers_qa"
allItems = jenkinsInstance.items
if ("${JOB_NAME}" == jobName) {
chosenJob = allItems.findAll{ job -> job.name.matches("synchronize_build_numbers_release") }
chosenJob.each{ job -> job.nextBuildNumber = "${BUILD_NUMBER}".toInteger() }
} else {
chosenJobs = allItems.findAll{ job -> job.name.matches(searchedJobName) }
buildNumber = chosenJobs.collect{ job -> job.nextBuildNumber }.max()
chosenJobs.each{ job -> job.nextBuildNumber = buildNumber }
}
return [:]Thanks for help ;)