Skip to content

Commit 56e587f

Browse files
authored
Merge pull request jenkinsci#620 from jglick/causeOfStoppage
Honor `causeOfStoppage` even when process exits with code 0
2 parents f3ebadc + 49a7939 commit 56e587f

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -678,20 +678,19 @@ private interface OutputSupplier {
678678
byte[] produce() throws IOException, InterruptedException;
679679
}
680680
private void handleExit(int exitCode, OutputSupplier output) throws IOException, InterruptedException {
681-
Throwable originalCause = causeOfStoppage;
682-
if ((returnStatus && originalCause == null) || exitCode == 0) {
683-
getContext().onSuccess(returnStatus ? exitCode : returnStdout ? new String(output.produce(), StandardCharsets.UTF_8) : null);
684-
} else {
681+
if (causeOfStoppage != null) {
682+
getContext().onFailure(causeOfStoppage);
683+
} else if (returnStatus) {
684+
getContext().onSuccess(exitCode);
685+
} else if (exitCode != 0) {
685686
if (returnStdout) {
686687
_listener().getLogger().write(output.produce()); // diagnostic
687688
}
688-
if (originalCause != null) {
689-
// JENKINS-28822: Use the previous cause instead of throwing a new AbortException
690-
_listener().getLogger().println("script returned exit code " + exitCode);
691-
getContext().onFailure(originalCause);
692-
} else {
693-
getContext().onFailure(new AbortException("script returned exit code " + exitCode));
694-
}
689+
getContext().onFailure(new AbortException("script returned exit code " + exitCode));
690+
} else if (returnStdout) {
691+
getContext().onSuccess(new String(output.produce(), StandardCharsets.UTF_8));
692+
} else {
693+
getContext().onSuccess(null);
695694
}
696695
listener().getLogger().close();
697696
}

src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ private static final class HelloNote extends ConsoleNote<Run<?, ?>> {
778778
j.waitForCompletion(b);
779779
// Would have succeeded before https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/75.
780780
j.assertBuildStatus(Result.ABORTED, b);
781-
j.waitForMessage("Timeout has been exceeded", b); // TODO assertLogContains fails unless a sleep is introduced; possible race condition in waitForCompletion
781+
j.assertLogContains("Timeout has been exceeded", b);
782782
}
783783

784784
@Issue("JENKINS-62014")

0 commit comments

Comments
 (0)