Skip to content

Commit 3f5aca4

Browse files
authored
Add the step args to the display name. (#38)
1 parent ea7765f commit 3f5aca4

File tree

5 files changed

+46
-22
lines changed

5 files changed

+46
-22
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,8 @@ public Collection<Action> getPipelineActions() {
273273
public void setPipelineActions(Collection<Action> pipelineActions) {
274274
this.pipelineActions = pipelineActions;
275275
}
276+
277+
public String getArgumentsAsString() {
278+
return PipelineNodeUtil.getArgumentsAsString(node);
279+
}
276280
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import javax.annotation.Nullable;
1010
import org.jenkinsci.plugins.pipeline.StageStatus;
1111
import org.jenkinsci.plugins.pipeline.SyntheticStage;
12+
import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;
1213
import org.jenkinsci.plugins.workflow.actions.LabelAction;
1314
import org.jenkinsci.plugins.workflow.actions.LogAction;
1415
import org.jenkinsci.plugins.workflow.actions.QueueItemAction;
@@ -105,6 +106,13 @@ public static boolean isParallelBranch(@Nullable FlowNode node) {
105106
&& node.getAction(ThreadNameAction.class) != null;
106107
}
107108

109+
public static String getArgumentsAsString(@Nullable FlowNode node) {
110+
if (node != null) {
111+
return ArgumentsAction.getStepArgumentsAsString(node);
112+
}
113+
return "";
114+
}
115+
108116
/**
109117
* Gives cause of block for declarative style plugin where agent (node block) is declared inside a
110118
* stage.

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ private List<PipelineStep> parseSteps(List<FlowNodeWrapper> stepNodes) {
2929
if (flowNodeWrapper.getStatus().getState() != BlueRun.BlueRunState.FINISHED) {
3030
state = flowNodeWrapper.getStatus().getState().name().toLowerCase(Locale.ROOT);
3131
}
32+
String displayName = flowNodeWrapper.getDisplayName();
33+
String stepArguments = flowNodeWrapper.getArgumentsAsString();
34+
if (stepArguments != null && !stepArguments.isEmpty()) {
35+
displayName = stepArguments + " - " + displayName;
36+
}
3237
return new PipelineStep(
3338
Integer.parseInt(
3439
flowNodeWrapper
3540
.getId()), // TODO no need to parse it BO returns a string even though
3641
// the datatype is number on the frontend
37-
flowNodeWrapper.getDisplayName(),
42+
displayName,
3843
state,
3944
50, // TODO how ???
4045
flowNodeWrapper.getType().name(),

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

+26-21
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,30 @@ public void unstableSmokes() throws Exception {
2424
j, "unstableSmokes", "unstableSmokes.jenkinsfile", Result.FAILURE);
2525
PipelineStepApi api = new PipelineStepApi(run);
2626

27-
// We don't need to prefix with 'Branch: ' as these are not Declarative parallel stages.
2827
String unstableOneId = TestUtils.getNodesByDisplayName(run, "unstable-one").get(0).getId();
2928
String successId = TestUtils.getNodesByDisplayName(run, "success").get(0).getId();
3029
String unstableTwoId = TestUtils.getNodesByDisplayName(run, "unstable-two").get(0).getId();
3130
String failureID = TestUtils.getNodesByDisplayName(run, "failure").get(0).getId();
3231

3332
List<PipelineStep> steps = api.getSteps(unstableOneId).getSteps();
3433
assertThat(steps, hasSize(3));
35-
assertThat(steps.get(0).getName(), is("Print Message"));
36-
assertThat(steps.get(1).getName(), is("Set stage result to unstable"));
37-
assertThat(steps.get(2).getName(), is("Print Message"));
34+
assertThat(steps.get(0).getName(), is("foo - Print Message"));
35+
assertThat(steps.get(1).getName(), is("oops-one - Set stage result to unstable"));
36+
assertThat(steps.get(2).getName(), is("bar - Print Message"));
3837

3938
steps = api.getSteps(successId).getSteps();
4039
assertThat(steps, hasSize(1));
41-
assertThat(steps.get(0).getName(), is("Print Message"));
40+
assertThat(steps.get(0).getName(), is("baz - Print Message"));
4241

4342
steps = api.getSteps(unstableTwoId).getSteps();
4443
assertThat(steps, hasSize(2));
45-
assertThat(steps.get(0).getName(), is("Error signal"));
46-
assertThat(steps.get(1).getName(), is("Set stage result to unstable"));
44+
assertThat(steps.get(0).getName(), is("will-be-caught - Error signal"));
45+
assertThat(steps.get(1).getName(), is("oops-two - Set stage result to unstable"));
4746

4847
steps = api.getSteps(failureID).getSteps();
4948
assertThat(steps, hasSize(2));
50-
assertThat(steps.get(0).getName(), is("Set stage result to unstable"));
51-
assertThat(steps.get(1).getName(), is("Error signal"));
49+
assertThat(steps.get(0).getName(), is("oops-masked - Set stage result to unstable"));
50+
assertThat(steps.get(1).getName(), is("oops-failure - Error signal"));
5251
}
5352

5453
@Test
@@ -58,29 +57,35 @@ public void complexParallelBranchesHaveCorrectSteps() throws Exception {
5857
WorkflowRun run =
5958
TestUtils.createAndRunJob(
6059
j, "complexParallelSmokes", "complexParallelSmokes.jenkinsfile", Result.SUCCESS);
61-
PipelineStepApi api = new PipelineStepApi(run);
62-
List<PipelineStep> steps = api.getSteps("1").getSteps();
63-
assertThat(steps, hasSize(0));
6460

6561
// Dynamically find the nodes which will be returned by the GraphAPI
62+
String nonParallelId =
63+
TestUtils.getNodesByDisplayName(run, "Non-Parallel Stage").get(0).getId();
64+
// We need to prefix with 'Branch: ' as these are Declarative parallel stages.
6665
String branchAId = TestUtils.getNodesByDisplayName(run, "Branch: Branch A").get(0).getId();
6766
String branchBId = TestUtils.getNodesByDisplayName(run, "Branch: Branch B").get(0).getId();
6867
String branchCId = TestUtils.getNodesByDisplayName(run, "Branch: Branch C").get(0).getId();
6968
String branchNested1Id = TestUtils.getNodesByDisplayName(run, "Nested 1").get(0).getId();
7069
String branchNested2Id = TestUtils.getNodesByDisplayName(run, "Nested 2").get(0).getId();
7170

71+
// Check 'Non-Parallel Stage'
72+
PipelineStepApi api = new PipelineStepApi(run);
73+
List<PipelineStep> steps = api.getSteps(nonParallelId).getSteps();
74+
assertThat(steps, hasSize(2));
75+
assertThat(steps.get(0).getName(), is("This stage will be executed first. - Print Message"));
76+
assertThat(steps.get(1).getName(), is("Print Message"));
77+
7278
// Check 'Branch A'
73-
api = new PipelineStepApi(run);
7479
steps = api.getSteps(branchAId).getSteps();
7580
assertThat(steps, hasSize(2));
76-
assertThat(steps.get(0).getName(), is("Print Message"));
77-
assertThat(steps.get(1).getName(), is("Print Message"));
81+
assertThat(steps.get(0).getName(), is("On Branch A - 1 - Print Message"));
82+
assertThat(steps.get(1).getName(), is("On Branch A - 2 - Print Message"));
7883

7984
// Check 'Branch B'
8085
steps = api.getSteps(branchBId).getSteps();
8186
assertThat(steps, hasSize(2));
82-
assertThat(steps.get(0).getName(), is("Print Message"));
83-
assertThat(steps.get(1).getName(), is("Print Message"));
87+
assertThat(steps.get(0).getName(), is("On Branch B - 1 - Print Message"));
88+
assertThat(steps.get(1).getName(), is("On Branch B - 2 - Print Message"));
8489

8590
// Check 'Branch C'
8691
steps = api.getSteps(branchCId).getSteps();
@@ -89,13 +94,13 @@ public void complexParallelBranchesHaveCorrectSteps() throws Exception {
8994
// Check 'Nested 1'
9095
steps = api.getSteps(branchNested1Id).getSteps();
9196
assertThat(steps, hasSize(2));
92-
assertThat(steps.get(0).getName(), is("Print Message"));
93-
assertThat(steps.get(1).getName(), is("Print Message"));
97+
assertThat(steps.get(0).getName(), is("In stage Nested 1 - 1 within Branch C - Print Message"));
98+
assertThat(steps.get(1).getName(), is("In stage Nested 1 - 2 within Branch C - Print Message"));
9499

95100
// Check 'Nested 2'
96101
steps = api.getSteps(branchNested2Id).getSteps();
97102
assertThat(steps, hasSize(2));
98-
assertThat(steps.get(0).getName(), is("Print Message"));
99-
assertThat(steps.get(1).getName(), is("Print Message"));
103+
assertThat(steps.get(0).getName(), is("In stage Nested 2 - 1 within Branch C - Print Message"));
104+
assertThat(steps.get(1).getName(), is("In stage Nested 2 - 2 within Branch C - Print Message"));
100105
}
101106
}

src/test/resources/io/jenkins/plugins/pipelinegraphview/utils/complexParallelSmokes.jenkinsfile

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pipeline {
44
stage('Non-Parallel Stage') {
55
steps {
66
echo 'This stage will be executed first.'
7+
// Test empty/no args for step
8+
echo ''
79
}
810
}
911
stage('Parallel Stage') {

0 commit comments

Comments
 (0)