Skip to content

Commit 7535b96

Browse files
authored
Return console stages in order. (#136)
1 parent 1d19cc8 commit 7535b96

File tree

6 files changed

+148
-11
lines changed

6 files changed

+148
-11
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/frontend/pipeline-console-view/pipeline-console/main/pipeline-console.scss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,17 @@ div.step-detail-group {
214214
display: flex;
215215
}
216216

217-
218-
div.detail-element{
217+
div.detail-element {
219218
display: flex;
220-
width:100%;
219+
width: 100%;
221220
font-size: var(--font-size-monospace);
222221
vertical-align: middle;
223222
margin-left: 10px;
224223
line-height: 1.66 !important;
225224
padding: 3px;
226225
}
227226

228-
.capitalize {
227+
.capitalize {
229228
text-transform: lowercase;
230229
}
231230

@@ -244,4 +243,4 @@ div.detail-element:last-child {
244243

245244
svg.detail-icon {
246245
margin-right: 10px;
247-
}
246+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,15 @@ public PipelineStepList getSteps(String stageId) {
9090
return new PipelineStepList(parseSteps(stepNodes, stageId));
9191
}
9292

93+
/* Returns a PipelineStepList, sorted by stageId and Id. */
9394
public PipelineStepList getAllSteps() {
9495
PipelineStepVisitor builder = new PipelineStepVisitor(run, null);
9596
Map<String, List<FlowNodeWrapper>> stepNodes = builder.getAllSteps();
9697
PipelineStepList allSteps = new PipelineStepList();
9798
for (Map.Entry<String, List<FlowNodeWrapper>> entry : stepNodes.entrySet()) {
9899
allSteps.addAll(parseSteps(entry.getValue(), entry.getKey()));
99100
}
101+
allSteps.sort();
100102
return allSteps;
101103
}
102104
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ public List<PipelineStep> getSteps() {
1919
return steps;
2020
}
2121

22+
/* Sorts the list of PipelineSteps by stageId and Id. */
23+
public void sort() {
24+
this.steps.sort(
25+
(lhs, rhs) -> {
26+
if (lhs.getStageId().equals(rhs.getStageId())) {
27+
return Integer.compare(
28+
Integer.parseInt(lhs.getStageId()), Integer.parseInt(rhs.getStageId()));
29+
} else {
30+
return Integer.compare(lhs.getId(), rhs.getId());
31+
}
32+
});
33+
}
34+
2235
public void addAll(List<PipelineStep> steps) {
2336
this.steps.addAll(steps);
2437
}

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,91 @@ public void complexParallelBranchesHaveCorrectSteps() throws Exception {
103103
assertThat(steps.get(0).getName(), is("In stage Nested 2 - 1 within Branch C - Print Message"));
104104
assertThat(steps.get(1).getName(), is("In stage Nested 2 - 2 within Branch C - Print Message"));
105105
}
106+
107+
@Test
108+
public void nestedStagesHaveCorrectSteps() throws Exception {
109+
// It's a bit dirty, but do this in one to avoid reloading and rerunning the job (as it takes a
110+
// long time)
111+
WorkflowRun run =
112+
TestUtils.createAndRunJob(j, "nestedStages", "nestedStages.jenkinsfile", Result.SUCCESS);
113+
114+
String childAId = TestUtils.getNodesByDisplayName(run, "Child A").get(0).getId();
115+
String childBId = TestUtils.getNodesByDisplayName(run, "Child B").get(0).getId();
116+
String grandchildBId = TestUtils.getNodesByDisplayName(run, "Grandchild B").get(0).getId();
117+
String childCId = TestUtils.getNodesByDisplayName(run, "Child C").get(0).getId();
118+
String grandchildCId = TestUtils.getNodesByDisplayName(run, "Grandchild C").get(0).getId();
119+
String greatGrandchildCId =
120+
TestUtils.getNodesByDisplayName(run, "Great-grandchild C").get(0).getId();
121+
122+
PipelineStepApi api = new PipelineStepApi(run);
123+
124+
// Check 'Child A'
125+
List<PipelineStep> steps = api.getSteps(childAId).getSteps();
126+
assertThat(steps, hasSize(1));
127+
assertThat(steps.get(0).getName(), is("In child A - Print Message"));
128+
129+
// Check 'Child A'
130+
steps = api.getSteps(childBId).getSteps();
131+
assertThat(steps, hasSize(0));
132+
133+
// Check 'Grandchild B'
134+
steps = api.getSteps(grandchildBId).getSteps();
135+
assertThat(steps, hasSize(1));
136+
assertThat(steps.get(0).getName(), is("In grandchild B - Print Message"));
137+
138+
// Check 'Child C'
139+
steps = api.getSteps(childCId).getSteps();
140+
assertThat(steps, hasSize(0));
141+
142+
// Check 'Grandchild C'
143+
steps = api.getSteps(grandchildCId).getSteps();
144+
assertThat(steps, hasSize(0));
145+
146+
// Check 'Great-Grandchild C'
147+
steps = api.getSteps(greatGrandchildCId).getSteps();
148+
assertThat(steps, hasSize(1));
149+
assertThat(steps.get(0).getName(), is("In great-grandchild C - Print Message"));
150+
}
151+
152+
@Test
153+
public void getAllStepsReturnsStepsForComplexParallelBranches() throws Exception {
154+
// It's a bit dirty, but do this in one to avoid reloading and rerunning the job (as it takes a
155+
// long time)
156+
WorkflowRun run =
157+
TestUtils.createAndRunJob(
158+
j, "complexParallelSmokes", "complexParallelSmokes.jenkinsfile", Result.SUCCESS);
159+
160+
// Check 'Non-Parallel Stage'
161+
PipelineStepApi api = new PipelineStepApi(run);
162+
163+
List<PipelineStep> steps = api.getAllSteps().getSteps();
164+
assertThat(steps, hasSize(10));
165+
assertThat(steps.get(0).getName(), is("This stage will be executed first. - Print Message"));
166+
assertThat(steps.get(1).getName(), is("Print Message"));
167+
assertThat(steps.get(2).getName(), is("On Branch A - 1 - Print Message"));
168+
assertThat(steps.get(3).getName(), is("On Branch A - 2 - Print Message"));
169+
assertThat(steps.get(4).getName(), is("On Branch B - 1 - Print Message"));
170+
assertThat(steps.get(5).getName(), is("On Branch B - 2 - Print Message"));
171+
172+
assertThat(steps.get(6).getName(), is("In stage Nested 1 - 1 within Branch C - Print Message"));
173+
assertThat(steps.get(7).getName(), is("In stage Nested 1 - 2 within Branch C - Print Message"));
174+
assertThat(steps.get(8).getName(), is("In stage Nested 2 - 1 within Branch C - Print Message"));
175+
assertThat(steps.get(9).getName(), is("In stage Nested 2 - 2 within Branch C - Print Message"));
176+
}
177+
178+
@Test
179+
public void getAllStepsReturnsStepsForNestedStages() throws Exception {
180+
// It's a bit dirty, but do this in one to avoid reloading and rerunning the job (as it takes a
181+
// long time)
182+
WorkflowRun run =
183+
TestUtils.createAndRunJob(j, "nestedStages", "nestedStages.jenkinsfile", Result.SUCCESS);
184+
185+
PipelineStepApi api = new PipelineStepApi(run);
186+
187+
List<PipelineStep> steps = api.getAllSteps().getSteps();
188+
assertThat(steps, hasSize(3));
189+
assertThat(steps.get(0).getName(), is("In child A - Print Message"));
190+
assertThat(steps.get(1).getName(), is("In grandchild B - Print Message"));
191+
assertThat(steps.get(2).getName(), is("In great-grandchild C - Print Message"));
192+
}
106193
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
pipeline {
2+
agent any
3+
stages {
4+
stage("Parennt") {
5+
stages {
6+
stage ("Child A") {
7+
steps {
8+
echo "In child A"
9+
}
10+
}
11+
stage ("Child B") {
12+
stages {
13+
stage("Grandchild B") {
14+
steps {
15+
echo "In grandchild B"
16+
}
17+
}
18+
}
19+
}
20+
stage ("Child C") {
21+
stages {
22+
stage("Grandchild C") {
23+
stages {
24+
stage("Great-grandchild C") {
25+
steps {
26+
echo "In great-grandchild C"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)