Skip to content

Commit

Permalink
[JENKINS-11257]: Aborting the parent job will abort building/queued c…
Browse files Browse the repository at this point in the history
…hild jobs
  • Loading branch information
ad22 committed May 15, 2016
1 parent 2caa77a commit 30ec984
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@
import hudson.tasks.Builder;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.Build;
import hudson.model.Queue;
import hudson.model.Result;
import hudson.model.Cause;
import hudson.model.Cause.UpstreamCause;
import hudson.util.IOException2;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.stapler.DataBoundConstructor;
import jenkins.model.Jenkins;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.CancellationException;
import java.lang.InterruptedException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

Expand Down Expand Up @@ -151,6 +158,54 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
}
}
}
} catch (InterruptedException y) {
for (BlockableBuildTriggerConfig config : configs) {
Queue buildQueue = Jenkins.getInstance().getQueue();
for (Queue.Item queueItem : buildQueue.getItems()) {
List<Cause> causes = queueItem.getCauses();
boolean isBuildCause = false;
for (Cause c : causes) {
if (c == null) {
continue;
}
if (!(c instanceof UpstreamCause)) {
continue;
}
UpstreamCause upstreamCause = (UpstreamCause) c;
if (upstreamCause.pointsTo(build)) {
isBuildCause = true;
break;
}
}
if (isBuildCause) {
try {
queueItem.doCancelQueue();
} catch (javax.servlet.ServletException ex) {
// pass
}
}
}

for (Queue.LeftItem queueLeftItem : buildQueue.getLeftItems()) {
Build exec = (Build) queueLeftItem.getExecutable();
if (exec == null) {
continue;
}
UpstreamCause cause = (UpstreamCause) exec.getCause(UpstreamCause.class);
if (cause == null) {
continue;
}
if (cause.pointsTo(build)) {
try {
listener.getLogger().println("Aborting " + HyperlinkNote.encodeTo('/' + exec.getUrl(), exec.getFullDisplayName()));
exec.doStop();
} catch (javax.servlet.ServletException ex) {
// pass, build has already completed or aborted
}
}
}
}
throw new InterruptedException();
} catch (ExecutionException e) {
throw new IOException2(e); // can't happen, I think.
}
Expand Down

0 comments on commit 30ec984

Please sign in to comment.