Synchronized build numbers

26 views
Skip to first unread message

Maciej Gąsiorowski

unread,
Apr 2, 2015, 6:24:10 AM4/2/15
to jenkins...@googlegroups.com
Hi,
I have 3 jobs:
  1. Debug version (after commits).
  2. QA version (manual, timer)
  3. Release version (triggered by 2, manual).

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 [:]

And it works, but I would like to make this script was more universal.

Thanks for help ;)

Reply all
Reply to author
Forward
0 new messages