use of org.jenkinsci.plugins.workflow.steps.FlowInterruptedException in project workflow-cps-plugin by jenkinsci.
the class CpsBodyExecution method cancel.
@Override
public boolean cancel(final CauseOfInterruption... causes) {
// 'stopped' and 'thread' are updated atomically
CpsThread t;
synchronized (this) {
// already complete
if (isDone())
return false;
// TODO should perhaps rather override cancel(Throwable) and make this overload just delegate to that one
stopped = new FlowInterruptedException(Result.ABORTED, causes);
t = this.thread;
}
if (t != null) {
t.getExecution().runInCpsVmThread(new FutureCallback<CpsThreadGroup>() {
@Override
public void onSuccess(CpsThreadGroup g) {
// Similar to getCurrentExecutions but we want the raw CpsThread, not a StepExecution; cf. CpsFlowExecution.interrupt
Map<FlowHead, CpsThread> m = new LinkedHashMap<>();
for (CpsThread t : thread.group.threads.values()) {
m.put(t.head, t);
}
for (CpsThread t : Iterators.reverse(ImmutableList.copyOf(m.values()))) {
LinearBlockHoppingScanner scanner = new LinearBlockHoppingScanner();
scanner.setup(t.head.get());
for (FlowNode node : scanner) {
if (node.getId().equals(startNodeId)) {
t.stop(stopped);
break;
}
}
}
}
@Override
public void onFailure(Throwable t) {
LOGGER.log(Level.WARNING, "could not cancel " + context + " with " + Arrays.toString(causes), t);
}
});
} else {
// if it hasn't begun executing, we'll stop it when
// it begins.
}
return true;
}
use of org.jenkinsci.plugins.workflow.steps.FlowInterruptedException in project workflow-job-plugin by jenkinsci.
the class WorkflowRun method doKill.
/**
* Immediately kills the build.
*/
@RequirePOST
public void doKill() {
checkPermission(Item.CANCEL);
if (!isBuilding() || /* probably redundant, but just to be sure */
execution == null) {
return;
}
if (listener != null) {
listener.getLogger().println("Hard kill!");
}
// ensures isInProgress returns false
execution = null;
FlowInterruptedException suddenDeath = new FlowInterruptedException(Result.ABORTED);
finish(Result.ABORTED, suddenDeath);
executionPromise.setException(suddenDeath);
// TODO CpsFlowExecution.onProgramEnd does some cleanup which we cannot access here; perhaps need a FlowExecution.halt(Throwable) API?
}
Aggregations