forked from cloudbees/jenkins-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cancel-running-builds.groovy
23 lines (23 loc) · 1010 Bytes
/
cancel-running-builds.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public int cancelRunning() {
// Cancel running builds.
def numCancels = 0;
for (job in this.hudson.instance.items) {
for (build in job.builds) {
if (build == this.build) { continue; } // don't cancel ourself!
if (!build.hasProperty('causes')) { continue; }
if (!build.isBuilding()) { continue; }
for (cause in build.causes) {
if (!cause.hasProperty('upstreamProject')) { continue; }
if (cause.upstreamProject == this.upstreamProject &&
cause.upstreamBuild == this.upstreamBuild) {
this.printer.println('Stopping ' + build.toString());
build.doStop();
this.printer.println(build.toString() + ' stopped.');
numCancels++;
break;
}
}
}
}
return numCancels;
}