Skip to content

Commit

Permalink
avoid printing too long argument lists during FlowNode visualization
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ArturHarasimiuk committed Apr 25, 2018
1 parent 6236d9c commit e4d35e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.structs.describable.DescribableModel;
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
Expand Down Expand Up @@ -197,7 +198,7 @@ public static String getStepArgumentsAsString(@Nonnull FlowNode n) {
StepDescriptor descriptor = ((StepNode) n).getDescriptor();
if (descriptor != null) { // Null if plugin providing descriptor was uninstalled
Map<String, Object> filteredArgs = getFilteredArguments(n);
return descriptor.argumentsToString(filteredArgs);
return StringUtils.substring(descriptor.argumentsToString(filteredArgs), 0, 80);
}
}
return null; // non-StepNode nodes can't have step arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,5 +450,33 @@ private List<FlowNode> enclosingBlocksIncludingNode(FlowNode node) {
encl.addAll(node.getEnclosingBlocks());
return encl;
}
}

@Test
public void testLongStepArguments() throws Exception {
rr.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob job = rr.j.createProject(WorkflowJob.class, "testLongStepArguments");

job.setDefinition(new CpsFlowDefinition(
"node('master') {\n" +
" stage('weird') {\n" +
" 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" +
" }\n" +
"}\n")
);
WorkflowRun r = rr.j.buildAndAssertSuccess(job);

FlowExecution execution = r.getExecution();

DepthFirstScanner scan = new DepthFirstScanner();
for (FlowNode n : scan.allNodes(execution)) {
String args = ArgumentsAction.getStepArgumentsAsString(n);
if(args!=null) {
assertTrue(args.length() <= 80);
}
}
}
});
}
}

0 comments on commit e4d35e0

Please sign in to comment.