Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null) {
return;
}
Queue q = jenkins.getQueue();
// if the build is still in the queue, abort it.
// BuildTriggerListener will report the failure, so this method shouldn't call getContext().onFailure()
for (Queue.Item i : q.getItems()) {
BuildTriggerAction bta = i.getAction(BuildTriggerAction.class);
if (bta!=null && bta.getStepContext().equals(getContext())) {
q.cancel(i);
}
}
// if there's any in-progress build already, abort that.
// when the build is actually aborted, BuildTriggerListener will take notice and report the failure,