Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.ghprb.extensions.build;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Cause;
import hudson.model.Job;
import hudson.model.Queue;
Expand Down Expand Up @@ -52,31 +53,30 @@ private void cancelCurrentBuilds(Job<?, ?> project,
+ ", checking for queued items to cancel."
);

Queue queue = Jenkins.getInstance().getQueue();
Queue.Item queueItem = project.getQueueItem();
while (queueItem != null) {
GhprbCause qcause = null;
if (project instanceof AbstractProject<?, ?>) {
Queue queue = Jenkins.getInstance().getQueue();
for (Queue.Item queueItem : queue.getItems((AbstractProject<?, ?>) project)) {
GhprbCause qcause = null;

for (Cause cause : queueItem.getCauses()) {
if (cause instanceof GhprbCause) {
qcause = (GhprbCause) cause;
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);
}
}
}

queueItem = project.getQueueItem();
}

LOGGER.log(Level.FINER, "New build scheduled for " + project.getName() + " on PR # " + prId);
Expand Down