Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Isaac Cohen added cancel-builds-same-job b71fa94 Jan 6, 2016
0 contributors

Users who have contributed to this file

17 lines (14 sloc) 547 Bytes
/*
Author: Isaac S Cohen
This script works with workflow to cancel other running builds for the same job
Use case: many build may go to QA, but only the build that is accepted is needed,
the other builds in the workflow should be aborted
*/
def jobname = env.JOB_NAME
def buildnum = env.BUILD_NUMBER.toInteger()
def job = Jenkins.instance.getItemByFullName(jobname)
for (build in job.builds) {
if (!build.isBuilding()) { continue; }
if (buildnum == build.getNumber().toInteger()) { continue; println "equals" }
build.doStop();
}
You can’t perform that action at this time.