Skip to content

Commit e4d35e0

Browse files
avoid printing too long argument lists during FlowNode visualization
In some cases it is possible that node argument will be impossible to wrap properly and is displayed as single line. In this case pipeline steps view becomes hard to read because right most columns are moved beyond the screen. this requires scrolling which is not so convenient. Also status colum is outside of screen. This change cuts arguments list to 80 characters which should be fine for most of usages. Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
1 parent 6236d9c commit e4d35e0

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/main/java/org/jenkinsci/plugins/workflow/actions/ArgumentsAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import javax.annotation.CheckForNull;
4040
import javax.annotation.Nonnull;
4141
import org.apache.commons.collections.CollectionUtils;
42+
import org.apache.commons.lang.StringUtils;
4243
import org.jenkinsci.plugins.structs.describable.DescribableModel;
4344
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable;
4445
import org.jenkinsci.plugins.workflow.graph.FlowNode;
@@ -197,7 +198,7 @@ public static String getStepArgumentsAsString(@Nonnull FlowNode n) {
197198
StepDescriptor descriptor = ((StepNode) n).getDescriptor();
198199
if (descriptor != null) { // Null if plugin providing descriptor was uninstalled
199200
Map<String, Object> filteredArgs = getFilteredArguments(n);
200-
return descriptor.argumentsToString(filteredArgs);
201+
return StringUtils.substring(descriptor.argumentsToString(filteredArgs), 0, 80);
201202
}
202203
}
203204
return null; // non-StepNode nodes can't have step arguments

src/test/java/org/jenkinsci/plugins/workflow/graph/FlowNodeTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,5 +450,33 @@ private List<FlowNode> enclosingBlocksIncludingNode(FlowNode node) {
450450
encl.addAll(node.getEnclosingBlocks());
451451
return encl;
452452
}
453-
}
454453

454+
@Test
455+
public void testLongStepArguments() throws Exception {
456+
rr.addStep(new Statement() {
457+
@Override
458+
public void evaluate() throws Throwable {
459+
WorkflowJob job = rr.j.createProject(WorkflowJob.class, "testLongStepArguments");
460+
461+
job.setDefinition(new CpsFlowDefinition(
462+
"node('master') {\n" +
463+
" stage('weird') {\n" +
464+
" echo 'lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so,lib01.so'\n" +
465+
" }\n" +
466+
"}\n")
467+
);
468+
WorkflowRun r = rr.j.buildAndAssertSuccess(job);
469+
470+
FlowExecution execution = r.getExecution();
471+
472+
DepthFirstScanner scan = new DepthFirstScanner();
473+
for (FlowNode n : scan.allNodes(execution)) {
474+
String args = ArgumentsAction.getStepArgumentsAsString(n);
475+
if(args!=null) {
476+
assertTrue(args.length() <= 80);
477+
}
478+
}
479+
}
480+
});
481+
}
482+
}

0 commit comments

Comments
 (0)