Skip to content

Commit

Permalink
Dont cancel other project's jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Maytee Chinavanichkit committed Apr 17, 2019
1 parent a0edc11 commit d63d51b
Showing 1 changed file with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Queue.Item> 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);
}
}
}
}
Expand Down

0 comments on commit d63d51b

Please sign in to comment.