|
37 | 37 | import hudson.tasks.BuildStepMonitor;
|
38 | 38 | import hudson.tasks.Builder;
|
39 | 39 | import hudson.model.Job;
|
| 40 | +import hudson.model.Item; |
40 | 41 | import hudson.model.Run;
|
| 42 | +import hudson.model.Build; |
| 43 | +import hudson.model.Queue; |
| 44 | +import hudson.model.Result; |
| 45 | +import hudson.model.Cause; |
| 46 | +import hudson.model.Cause.UpstreamCause; |
| 47 | +import hudson.util.RunList; |
41 | 48 | import hudson.util.IOException2;
|
42 | 49 | import org.kohsuke.accmod.Restricted;
|
43 | 50 | import org.kohsuke.stapler.DataBoundConstructor;
|
| 51 | +import jenkins.model.Jenkins; |
44 | 52 |
|
45 | 53 | import java.io.IOException;
|
46 | 54 | import java.util.*;
|
47 | 55 | import java.util.concurrent.CancellationException;
|
| 56 | +import java.lang.InterruptedException; |
48 | 57 | import java.util.concurrent.ExecutionException;
|
49 | 58 | import java.util.concurrent.Future;
|
50 | 59 |
|
@@ -151,6 +160,58 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
|
151 | 160 | }
|
152 | 161 | }
|
153 | 162 | }
|
| 163 | + } catch (InterruptedException y) { |
| 164 | + for (BlockableBuildTriggerConfig config : configs) { |
| 165 | + Queue buildQueue = Jenkins.getInstance().getQueue(); |
| 166 | + for (Queue.Item queueItem : buildQueue.getItems()) { |
| 167 | + List<Cause> causes = queueItem.getCauses(); |
| 168 | + boolean isBuildCause = false; |
| 169 | + for (Cause c : causes) { |
| 170 | + if (c == null) { |
| 171 | + continue; |
| 172 | + } |
| 173 | + if (!(c instanceof UpstreamCause)) { |
| 174 | + continue; |
| 175 | + } |
| 176 | + UpstreamCause upstreamCause = (UpstreamCause) c; |
| 177 | + if (upstreamCause.pointsTo(build)) { |
| 178 | + isBuildCause = true; |
| 179 | + break; |
| 180 | + } |
| 181 | + } |
| 182 | + if (isBuildCause) { |
| 183 | + try { |
| 184 | + queueItem.doCancelQueue(); |
| 185 | + } catch (javax.servlet.ServletException ex) { |
| 186 | + // pass |
| 187 | + } |
| 188 | + } |
| 189 | + } |
| 190 | + |
| 191 | + List<Job> projectList = config.getJobs(build.getRootBuild().getProject().getParent(), env); |
| 192 | + for (Job p : projectList) { |
| 193 | + Item item = Jenkins.getInstance().getItem(p.getFullName(), p, Item.class); |
| 194 | + for (Job job : item.getAllJobs()) { |
| 195 | + RunList runList = job.getNewBuilds(); |
| 196 | + for (Iterator<Build> it = runList.iterator(); it.hasNext(); ) { |
| 197 | + Build latestBuild = it.next(); |
| 198 | + UpstreamCause cause = (UpstreamCause) latestBuild.getCause(UpstreamCause.class); |
| 199 | + if (cause == null) { |
| 200 | + continue; |
| 201 | + } |
| 202 | + if (cause.pointsTo(build)) { |
| 203 | + try { |
| 204 | + listener.getLogger().println("Aborting " + HyperlinkNote.encodeTo('/' + latestBuild.getUrl(), latestBuild.getFullDisplayName())); |
| 205 | + latestBuild.doStop(); |
| 206 | + } catch (javax.servlet.ServletException ex) { |
| 207 | + // pass, build has already completed or aborted |
| 208 | + } |
| 209 | + } |
| 210 | + } |
| 211 | + } |
| 212 | + } |
| 213 | + } |
| 214 | + throw new InterruptedException(); |
154 | 215 | } catch (ExecutionException e) {
|
155 | 216 | throw new IOException2(e); // can't happen, I think.
|
156 | 217 | }
|
|
0 commit comments