From 8993df156e8ddeffa7682da8806a995571ac4f0a Mon Sep 17 00:00:00 2001 From: Stuart Rowe Date: Tue, 4 Apr 2023 16:24:04 -0700 Subject: [PATCH] Only add WarningAction when propagate: true (#110) * Only add WarningAction when propagate: true * Combine conditions to avoid nested if statement * Fix WarningAction tests by enabling propagate --- .../support/steps/build/BuildTriggerListener.java | 2 +- .../support/steps/build/BuildTriggerStepTest.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerListener.java b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerListener.java index 0982132a..7fa10781 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerListener.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerListener.java @@ -56,7 +56,7 @@ public void onCompleted(Run run, @NonNull TaskListener listener) { try { stepContext.get(TaskListener.class).getLogger().println("Build " + ModelHyperlinkNote.encodeTo("/" + run.getUrl(), run.getFullDisplayName()) + " completed: " + result.toString()); - if (result != Result.SUCCESS) { + if (trigger.propagate && result != Result.SUCCESS) { stepContext.get(FlowNode.class).addOrReplaceAction(new WarningAction(result)); } } catch (Exception e) { diff --git a/src/test/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerStepTest.java b/src/test/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerStepTest.java index e914dbdf..68c37e16 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerStepTest.java @@ -133,8 +133,8 @@ public class BuildTriggerStepTest { @Test public void failingBuildWithWarningAction() throws Exception { j.createFreeStyleProject("ds").getBuildersList().add(new FailureBuilder()); WorkflowJob upstream = j.jenkins.createProject(WorkflowJob.class, "us"); - upstream.setDefinition(new CpsFlowDefinition("build(job: 'ds', propagate: false)", true)); - WorkflowRun lastUpstream = j.buildAndAssertSuccess(upstream); + upstream.setDefinition(new CpsFlowDefinition("build(job: 'ds')", true)); + WorkflowRun lastUpstream = j.buildAndAssertStatus(Result.FAILURE, upstream); j.assertLogContains("completed: FAILURE", lastUpstream); FlowNode buildTriggerNode = findFirstNodeWithDescriptor(lastUpstream.getExecution(), BuildTriggerStep.DescriptorImpl.class); WarningAction action = buildTriggerNode.getAction(WarningAction.class); @@ -146,8 +146,8 @@ public class BuildTriggerStepTest { @Test public void unstableBuildWithWarningAction() throws Exception { j.createFreeStyleProject("ds").getBuildersList().add(new UnstableBuilder()); WorkflowJob upstream = j.jenkins.createProject(WorkflowJob.class, "us"); - upstream.setDefinition(new CpsFlowDefinition("build(job: 'ds', propagate: false)", true)); - WorkflowRun lastUpstream = j.buildAndAssertSuccess(upstream); + upstream.setDefinition(new CpsFlowDefinition("build(job: 'ds')", true)); + WorkflowRun lastUpstream = j.buildAndAssertStatus(Result.UNSTABLE, upstream); j.assertLogContains("completed: UNSTABLE", lastUpstream); FlowNode buildTriggerNode = findFirstNodeWithDescriptor(lastUpstream.getExecution(), BuildTriggerStep.DescriptorImpl.class); WarningAction action = buildTriggerNode.getAction(WarningAction.class); @@ -159,7 +159,7 @@ public class BuildTriggerStepTest { @Test public void successBuildNoWarningAction() throws Exception { j.createFreeStyleProject("ds"); WorkflowJob upstream = j.jenkins.createProject(WorkflowJob.class, "us"); - upstream.setDefinition(new CpsFlowDefinition("build(job: 'ds', propagate: false)", true)); + upstream.setDefinition(new CpsFlowDefinition("build(job: 'ds')", true)); WorkflowRun lastUpstream = j.buildAndAssertSuccess(upstream); j.assertLogContains("completed: SUCCESS", lastUpstream); FlowNode buildTriggerNode = findFirstNodeWithDescriptor(lastUpstream.getExecution(), BuildTriggerStep.DescriptorImpl.class);