From d63d51b5f6eee7f249003fc0a9c3b314d2a1ebfc Mon Sep 17 00:00:00 2001 From: Maytee Chinavanichkit Date: Wed, 17 Apr 2019 16:15:21 +0900 Subject: [PATCH] Dont cancel other project's jobs --- .../build/GhprbCancelBuildsOnUpdate.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/ghprb/extensions/build/GhprbCancelBuildsOnUpdate.java b/src/main/java/org/jenkinsci/plugins/ghprb/extensions/build/GhprbCancelBuildsOnUpdate.java index 99938cfe1..228181bcc 100644 --- a/src/main/java/org/jenkinsci/plugins/ghprb/extensions/build/GhprbCancelBuildsOnUpdate.java +++ b/src/main/java/org/jenkinsci/plugins/ghprb/extensions/build/GhprbCancelBuildsOnUpdate.java @@ -18,6 +18,7 @@ import org.jenkinsci.plugins.ghprb.extensions.GhprbProjectExtension; import org.kohsuke.stapler.DataBoundConstructor; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -53,26 +54,28 @@ protected void cancelCurrentBuilds(Job project, ); Queue queue = Jenkins.getInstance().getQueue(); - Queue.Item[] queueItems = queue.getItems(); - for (Queue.Item queueItem : queueItems) { - GhprbCause qcause = null; - - for (Cause cause : queueItem.getCauses()) { - if (cause instanceof GhprbCause) { - qcause = (GhprbCause) cause; + Queue.Item item = project.getQueueItem(); + if (item != null) { + List queueItems = queue.getItems(item.task); + for (Queue.Item queueItem : queueItems) { + GhprbCause qcause = null; + + for (Cause cause : queueItem.getCauses()) { + if (cause instanceof GhprbCause) { + qcause = (GhprbCause) cause; + } } - } - - if (qcause != null && qcause.getPullID() == prId) { - try { - LOGGER.log( - Level.FINER, - "Cancelling queued build of " + project.getName() + " for PR # " - + qcause.getPullID() + ", checking for queued items to cancel." - ); - queue.cancel(queueItem); - } catch (Exception e) { - LOGGER.log(Level.SEVERE, "Unable to cancel queued build", e); + if (qcause != null && qcause.getPullID() == prId) { + try { + LOGGER.log( + Level.FINER, + "Cancelling queued build of " + project.getName() + " for PR # " + + qcause.getPullID() + ", checking for queued items to cancel." + ); + queue.cancel(queueItem); + } catch (Exception e) { + LOGGER.log(Level.SEVERE, "Unable to cancel queued build", e); + } } } }