|
6 | 6 | import hudson.model.Run;
|
7 | 7 | import hudson.tasks.Builder;
|
8 | 8 | import hudson.util.DescribableList;
|
| 9 | +import org.jenkinsci.plugins.workflow.actions.WarningAction; |
9 | 10 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
|
| 11 | +import org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode; |
| 12 | +import org.jenkinsci.plugins.workflow.flow.FlowExecution; |
| 13 | +import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker; |
| 14 | +import org.jenkinsci.plugins.workflow.graph.FlowNode; |
10 | 15 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
|
| 16 | +import org.jenkinsci.plugins.workflow.job.WorkflowRun; |
11 | 17 | import org.junit.ClassRule;
|
12 | 18 | import org.junit.Rule;
|
13 | 19 | import org.junit.Test;
|
14 | 20 | import org.jvnet.hudson.test.BuildWatcher;
|
15 | 21 | import org.jvnet.hudson.test.FailureBuilder;
|
16 |
| -import org.jvnet.hudson.test.SleepBuilder; |
17 |
| -import org.jvnet.hudson.test.JenkinsRule; |
| 22 | +import org.jvnet.hudson.test.Issue; |
18 | 23 | import org.jvnet.hudson.test.LoggerRule;
|
| 24 | +import org.jvnet.hudson.test.JenkinsRule; |
| 25 | +import org.jvnet.hudson.test.SleepBuilder; |
| 26 | +import org.jvnet.hudson.test.UnstableBuilder; |
19 | 27 |
|
20 | 28 | import static org.junit.Assert.assertEquals;
|
| 29 | +import static org.junit.Assert.assertNotNull; |
21 | 30 |
|
22 | 31 | public class WaitForBuildStepTest {
|
23 | 32 |
|
@@ -63,4 +72,39 @@ public class WaitForBuildStepTest {
|
63 | 72 | us.setDefinition(new CpsFlowDefinition("waitForBuild runId: 'ds#1'", true));
|
64 | 73 | j.assertLogContains("is already complete", j.buildAndAssertSuccess(us));
|
65 | 74 | }
|
| 75 | + |
| 76 | + @Issue("JENKINS-70983") |
| 77 | + @Test public void waitForUnstableBuildWithWarningAction() throws Exception { |
| 78 | + FreeStyleProject ds = j.createFreeStyleProject("ds"); |
| 79 | + DescribableList<Builder, Descriptor<Builder>> buildersList = ds.getBuildersList(); |
| 80 | + buildersList.add(new SleepBuilder(500)); |
| 81 | + buildersList.add(new UnstableBuilder()); |
| 82 | + WorkflowJob us = j.jenkins.createProject(WorkflowJob.class, "us"); |
| 83 | + us.setDefinition(new CpsFlowDefinition( |
| 84 | + "def ds = build job: 'ds', waitForStart: true\n" + |
| 85 | + "def dsRunId = \"${ds.getFullProjectName()}#${ds.getNumber()}\"\n" + |
| 86 | + "try {\n" + |
| 87 | + " waitForBuild runId: dsRunId, propagate: true\n" + |
| 88 | + "} finally {\n" + |
| 89 | + " echo \"'ds' completed with status ${ds.getResult()}\"\n" + |
| 90 | + "}", true)); |
| 91 | + j.assertLogContains("'ds' completed with status UNSTABLE", j.buildAndAssertStatus(Result.UNSTABLE, us)); |
| 92 | + WorkflowRun lastUpstreamRun = us.getLastBuild(); |
| 93 | + FlowNode buildTriggerNode = findFirstNodeWithDescriptor(lastUpstreamRun.getExecution(), WaitForBuildStep.DescriptorImpl.class); |
| 94 | + WarningAction action = buildTriggerNode.getAction(WarningAction.class); |
| 95 | + assertNotNull(action); |
| 96 | + assertEquals(action.getResult(), Result.UNSTABLE); |
| 97 | + } |
| 98 | + |
| 99 | + private static FlowNode findFirstNodeWithDescriptor(FlowExecution execution, Class<WaitForBuildStep.DescriptorImpl> cls) { |
| 100 | + for (FlowNode node : new FlowGraphWalker(execution)) { |
| 101 | + if (node instanceof StepAtomNode) { |
| 102 | + StepAtomNode stepAtomNode = (StepAtomNode) node; |
| 103 | + if (cls.isInstance(stepAtomNode.getDescriptor())) { |
| 104 | + return stepAtomNode; |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + return null; |
| 109 | + } |
66 | 110 | }
|
0 commit comments