Skip to content

Commit cbfc1e3

Browse files
authored
Merge pull request #308 from jglick/catchError
Log a note when `catchError` sets build result
2 parents bf550f7 + 6a6e341 commit cbfc1e3

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/org/jenkinsci/plugins/workflow/steps/CatchErrorStep.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ public Object readResolve() {
248248
Functions.printStackTrace(t, listener.getLogger());
249249
}
250250
if (buildResult.isWorseThan(Result.SUCCESS)) {
251-
context.get(Run.class).setResult(buildResult);
251+
Run<?, ?> build = context.get(Run.class);
252+
Result currentResult = build.getResult();
253+
if (currentResult == null || buildResult.isWorseThan(currentResult)) {
254+
listener.getLogger().println("Setting overall build result to " + buildResult);
255+
} // otherwise WorkflowRun.setResult should be a no-op, so do not log anything
256+
build.setResult(buildResult);
252257
}
253258
if (stepResult.isWorseThan(Result.SUCCESS)) {
254259
context.get(FlowNode.class).addOrReplaceAction(new WarningAction(stepResult).withMessage(message));

src/test/java/org/jenkinsci/plugins/workflow/steps/CatchErrorStepTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public class CatchErrorStepTest {
118118
"}", true));
119119
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
120120
assertCatchError(r, b, Result.UNSTABLE, null, true);
121+
r.assertLogContains("Setting overall build result to UNSTABLE", b);
121122
}
122123

123124
@Test public void invalidBuildResult() throws Exception {

0 commit comments

Comments
 (0)