Skip to content

Commit

Permalink
WorkflowRun.doTerm and doKill need to redirect back to the build (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored Oct 19, 2022
1 parent 113b524 commit 6110f53
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ private void printLater(final StopState state, final String message) {

/** Sends {@link StepContext#onFailure} to all running (leaf) steps. */
@RequirePOST
public void doTerm() {
public HttpResponse doTerm() {
checkPermission(Item.CANCEL);
if (!isInProgress() || /* redundant, but make FindBugs happy */ execution == null) {
return;
return HttpResponses.forwardToPreviousPage();
}
final Throwable x = new FlowInterruptedException(Result.ABORTED);
FlowExecution exec = getExecution();
Expand All @@ -454,7 +454,7 @@ public void doTerm() {
if (modified) {
saveWithoutFailing();
}
return;
return HttpResponses.forwardToPreviousPage();
}
}
Futures.addCallback(exec.getCurrentExecutions(/* cf. JENKINS-26148 */true), new FutureCallback<List<StepExecution>>() {
Expand All @@ -475,14 +475,15 @@ public void doTerm() {
@Override public void onFailure(@NonNull Throwable t) {}
});
printLater(StopState.KILL, "Click here to forcibly kill entire build");
return HttpResponses.forwardToPreviousPage();
}

/** Immediately kills the build. */
@RequirePOST
public void doKill() {
public HttpResponse doKill() {
checkPermission(Item.CANCEL);
if (!isBuilding() || /* probably redundant, but just to be sure */ execution == null) {
return;
return HttpResponses.forwardToPreviousPage();
}
synchronized (getMetadataGuard()) {
getListener().getLogger().println("Hard kill!");
Expand All @@ -495,6 +496,7 @@ public void doKill() {
finish(Result.ABORTED, suddenDeath);
getSettableExecutionPromise().setException(suddenDeath);
// TODO CpsFlowExecution.onProgramEnd does some cleanup which we cannot access here; perhaps need a FlowExecution.halt(Throwable) API?
return HttpResponses.forwardToPreviousPage();
}

@NonNull
Expand Down Expand Up @@ -870,8 +872,7 @@ public synchronized HttpResponse doStop() {
if (e != null) {
return e.doStop();
} else {
doKill();
return HttpResponses.forwardToPreviousPage();
return doKill();
}
}

Expand Down

0 comments on commit 6110f53

Please sign in to comment.