Skip to content

Commit

Permalink
Only add WarningAction when propagate: true (#110)
Browse files Browse the repository at this point in the history
* Only add WarningAction when propagate: true

* Combine conditions to avoid nested if statement

* Fix WarningAction tests by enabling propagate
  • Loading branch information
stuartrowe authored Apr 4, 2023
1 parent a823138 commit 8993df1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 8993df1

Please sign in to comment.