Skip to content

Commit ecb8c58

Browse files
authored
Handle skipped stages in parallel branches (#359)
1 parent cd408a1 commit ecb8c58

File tree

5 files changed

+103
-4
lines changed

5 files changed

+103
-4
lines changed

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,18 @@
119119
<url>https://repo.jenkins-ci.org/public/</url>
120120
</pluginRepository>
121121
</pluginRepositories>
122+
123+
<build>
124+
<plugins>
125+
<plugin>
126+
<groupId>org.jenkins-ci.tools</groupId>
127+
<artifactId>maven-hpi-plugin</artifactId>
128+
<configuration>
129+
<loggers>
130+
<io.jenkins.plugins.pipelinegraphview>FINEST</io.jenkins.plugins.pipelinegraphview>
131+
</loggers>
132+
</configuration>
133+
</plugin>
134+
</plugins>
135+
</build>
122136
</project>

src/main/java/io/jenkins/plugins/pipelinegraphview/treescanner/ParallelBlockRelationship.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import edu.umd.cs.findbugs.annotations.CheckForNull;
44
import edu.umd.cs.findbugs.annotations.NonNull;
55
import io.jenkins.plugins.pipelinegraphview.utils.NodeRunStatus;
6+
import io.jenkins.plugins.pipelinegraphview.utils.PipelineNodeUtil;
67
import java.util.ArrayDeque;
78
import java.util.ArrayList;
89
import java.util.List;
@@ -159,15 +160,16 @@ private void calculateTimings(WorkflowRun run) {
159160
branchStartNode.getId(),
160161
getBranchName(branchStartNode),
161162
this.branchStatuses.get(getBranchName(branchStartNode)));
162-
return new NodeRunStatus(this.branchStatuses.get(getBranchName(branchStartNode)));
163+
boolean skippedStage = PipelineNodeUtil.isSkippedStage(branchStartNode);
164+
return new NodeRunStatus(this.branchStatuses.get(getBranchName(branchStartNode)), skippedStage);
163165
}
164166

165167
/*
166168
* Gets TimingInfo for relationship.
167169
*/
168170
private void calculateStatuses(WorkflowRun run) {
169171
// The parallel API expects parallel end to be null if this is still running -
170-
// so only pass it if it;s not the start node;
172+
// so only pass it if its not the start node;
171173
FlowNode parallelEndNode = (this.start != this.end) ? this.end : null;
172174
this.branchStatuses = StatusAndTiming.computeBranchStatuses2(
173175
run, this.start, this.branchStarts, this.branchEnds, parallelEndNode);

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/NodeRunStatus.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public BlueRun.BlueRunState getState() {
6262
}
6363

6464
public NodeRunStatus(GenericStatus status) {
65+
this(status, false);
66+
}
67+
68+
public NodeRunStatus(GenericStatus status, boolean skipped) {
6569
GenericStatus coercedStatus = StatusAndTiming.coerceStatusApi(status, StatusAndTiming.CURRENT_API_VERSION);
6670
if (coercedStatus == null) {
6771
this.result = BlueRun.BlueRunResult.NOT_BUILT;
@@ -94,8 +98,13 @@ public NodeRunStatus(GenericStatus status) {
9498
this.state = BlueRun.BlueRunState.FINISHED;
9599
break;
96100
case NOT_EXECUTED:
97-
this.result = BlueRun.BlueRunResult.NOT_BUILT;
98-
this.state = BlueRun.BlueRunState.NOT_BUILT;
101+
if (skipped) {
102+
this.result = BlueRun.BlueRunResult.NOT_BUILT;
103+
this.state = BlueRun.BlueRunState.SKIPPED;
104+
} else {
105+
this.result = BlueRun.BlueRunResult.NOT_BUILT;
106+
this.state = BlueRun.BlueRunState.NOT_BUILT;
107+
}
99108
break;
100109
case QUEUED:
101110
this.result = BlueRun.BlueRunResult.UNKNOWN;

src/test/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineGraphApiTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,23 @@ public void stagesGetValidTimings() throws Exception {
379379
TestUtils.assertTimesInRange(n, checks.get(n.getName()));
380380
}
381381
}
382+
383+
@Issue("https://github.com/jenkinsci/pipeline-graph-view-plugin/issues/358")
384+
@Test
385+
public void gh_358_parallelStagesMarkedAsSkipped() throws Exception {
386+
WorkflowRun run = TestUtils.createAndRunJob(
387+
j,
388+
"gh_358_parallelStagesMarkedAsSkipped",
389+
"gh_358_parallelStagesMarkedAsSkipped.jenkinsfile",
390+
Result.FAILURE);
391+
392+
List<PipelineStage> stages = new PipelineGraphApi(run).createTree().getStages();
393+
String stagesString =
394+
TestUtils.collectStagesAsString(stages, (PipelineStage s) -> TestUtils.nodeNameAndStatus(s));
395+
396+
assertThat(
397+
stagesString,
398+
equalTo(
399+
"foo{success},first-parallel{failure}[bar{skipped},baz{failure}],second-parallel{skipped},Post Actions{success}"));
400+
}
382401
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
pipeline {
2+
agent none
3+
stages {
4+
stage("foo") {
5+
steps {
6+
echo "hello"
7+
}
8+
}
9+
10+
stage('first-parallel') {
11+
parallel {
12+
stage("bar") {
13+
when {
14+
expression {
15+
return false
16+
}
17+
}
18+
steps {
19+
echo "I will be skipped"
20+
}
21+
}
22+
23+
stage("baz") {
24+
steps {
25+
error "I will not be skipped but I will fail"
26+
}
27+
}
28+
}
29+
}
30+
31+
stage('second-parallel') {
32+
parallel {
33+
stage("bar2") {
34+
steps {
35+
echo "bar2 skipped for earlier failure"
36+
}
37+
}
38+
stage("baz2") {
39+
steps {
40+
echo "bar3 skipped for earlier failure"
41+
}
42+
}
43+
}
44+
}
45+
}
46+
47+
post {
48+
failure {
49+
echo "I have failed"
50+
}
51+
success {
52+
echo "I have succeeded"
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)