From 49a793989b49294661e59b31e9b82b898ee432a5 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 11 May 2026 17:52:40 -0400 Subject: [PATCH] Honor `causeOfStoppage` even when process exits with code 0 --- .../steps/durable_task/DurableTaskStep.java | 21 +++++++++---------- .../steps/durable_task/ShellStepTest.java | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java b/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java index 1c2521e0..5959c97b 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/steps/durable_task/DurableTaskStep.java @@ -678,20 +678,19 @@ private interface OutputSupplier { byte[] produce() throws IOException, InterruptedException; } private void handleExit(int exitCode, OutputSupplier output) throws IOException, InterruptedException { - Throwable originalCause = causeOfStoppage; - if ((returnStatus && originalCause == null) || exitCode == 0) { - getContext().onSuccess(returnStatus ? exitCode : returnStdout ? new String(output.produce(), StandardCharsets.UTF_8) : null); - } else { + if (causeOfStoppage != null) { + getContext().onFailure(causeOfStoppage); + } else if (returnStatus) { + getContext().onSuccess(exitCode); + } else if (exitCode != 0) { if (returnStdout) { _listener().getLogger().write(output.produce()); // diagnostic } - if (originalCause != null) { - // JENKINS-28822: Use the previous cause instead of throwing a new AbortException - _listener().getLogger().println("script returned exit code " + exitCode); - getContext().onFailure(originalCause); - } else { - getContext().onFailure(new AbortException("script returned exit code " + exitCode)); - } + getContext().onFailure(new AbortException("script returned exit code " + exitCode)); + } else if (returnStdout) { + getContext().onSuccess(new String(output.produce(), StandardCharsets.UTF_8)); + } else { + getContext().onSuccess(null); } listener().getLogger().close(); } diff --git a/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java b/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java index fbc0e7d5..246f9494 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java @@ -778,7 +778,7 @@ private static final class HelloNote extends ConsoleNote> { j.waitForCompletion(b); // Would have succeeded before https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/75. j.assertBuildStatus(Result.ABORTED, b); - j.waitForMessage("Timeout has been exceeded", b); // TODO assertLogContains fails unless a sleep is introduced; possible race condition in waitForCompletion + j.assertLogContains("Timeout has been exceeded", b); } @Issue("JENKINS-62014")