Skip to content

Commit

Permalink
Merge pull request #186 from jglick/FlowGraphTable-2
Browse files Browse the repository at this point in the history
Fixing display of `retry` step blocks
  • Loading branch information
jglick authored Jul 11, 2022
2 parents 7ef666c + 030af5b commit a1c7106
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,10 @@
<artifactId>pipeline-build-step</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-stage-step</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graph.StepNode;
import org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner;
import org.jenkinsci.plugins.workflow.graphanalysis.LinearBlockHoppingScanner;
import org.jenkinsci.plugins.workflow.visualization.table.FlowNodeViewColumn;
import org.jenkinsci.plugins.workflow.visualization.table.FlowNodeViewColumnDescriptor;

Expand Down Expand Up @@ -290,9 +291,9 @@ public String getDisplayName() {
} else if (node instanceof StepNode && node instanceof BlockStartNode) {
if (node.getAction(BodyInvocationAction.class) != null) {
// TODO cannot access StepAtomNode.effectiveFunctionName from here
List<FlowNode> parents = node.getParents();
if (parents.size() == 1) {
FlowNode start = parents.get(0);
LinearBlockHoppingScanner scanner = new LinearBlockHoppingScanner();
scanner.setup(node);
for (FlowNode start : scanner) {
if (start instanceof StepNode && start instanceof BlockStartNode && start.getPersistentAction(BodyInvocationAction.class) == null) {
String base = start.getDisplayFunctionName() + " block";
LabelAction a = node.getPersistentAction(LabelAction.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@
*/
package org.jenkinsci.plugins.workflow.support.visualization.table;

import org.apache.commons.lang.StringUtils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import static org.junit.Assert.fail;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.fail;

public class FlowGraphTableTest {

@Rule
Expand Down Expand Up @@ -95,4 +97,53 @@ public void corruptedFlowGraph() throws Exception {
}
}

@Test
public void rowDisplayName() throws Exception {
WorkflowJob p = r.createProject(WorkflowJob.class);
p.setDefinition(new CpsFlowDefinition(
"stage('start') {\n" +
" echo 'some message'\n" +
" def i = 0; retry(3) {\n" +
" if (++i < 3) error 'oops'\n" +
" node {\n" +
" isUnix()\n" +
" }\n" +
" }\n" +
"}\n" +
"stage('main') {\n" +
" parallel quick: {\n" +
" echo 'done'\n" +
" }, slow: {\n" +
" semaphore 'wait'\n" +
" }\n" +
"}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("wait/1", b);
FlowGraphTable t = new FlowGraphTable(b.getExecution());
t.build();
SemaphoreStep.success("wait/1", null);
r.waitForCompletion(b);
assertThat(t.getRows().stream().map(r -> StringUtils.repeat(" ", r.getTreeDepth()) + r.getDisplayName()).toArray(String[]::new), arrayContaining(
"Start of Pipeline",
" stage",
" stage block (start)",
" echo",
" retry",
" retry block",
" error",
" retry block",
" error",
" retry block",
" node",
" node block",
" isUnix",
" stage",
" stage block (main)",
" parallel",
" parallel block (Branch: quick)",
" echo",
" parallel block (Branch: slow)",
" semaphore"));
}

}

0 comments on commit a1c7106

Please sign in to comment.