use of org.jenkinsci.plugins.workflow.graph.FlowGraphWalker in project workflow-cps-plugin by jenkinsci.
the class CpsScriptTest method dumpError.
/**
* Picks up any errors recorded in {@link #exec}.
*/
private String dumpError() {
StringBuilder msg = new StringBuilder();
FlowGraphWalker walker = new FlowGraphWalker(exec);
for (FlowNode n : walker) {
ErrorAction e = n.getAction(ErrorAction.class);
if (e != null) {
msg.append(Functions.printThrowable(e.getError()));
}
}
return msg.toString();
}
use of org.jenkinsci.plugins.workflow.graph.FlowGraphWalker in project workflow-cps-plugin by jenkinsci.
the class CpsBodyExecutionTest method synchronousExceptionInBody.
/**
* When the body of a step is synchronous and explodes, the failure should be recorded and the pipeline job
* should move on.
*
* But instead, this hangs because CpsBodyExecution has a bug in how it handles this case.
* It tries to launch the body (in this case the 'bodyBlock' method) in a separate CPS thread,
* and puts the parent CPS thread on hold. Yet when the child CPS thread ends with an exception,
* it fails to record this result correctly, and it gets into the eternal sleep in which
* the parent CPS thread expects to be notified of the outcome of the child CPS thread, which
* never arrives.
*/
@Test
public void synchronousExceptionInBody() throws Exception {
WorkflowJob p = jenkins.createProject(WorkflowJob.class);
p.setDefinition(new CpsFlowDefinition("synchronousExceptionInBody()", true));
WorkflowRun b = jenkins.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));
jenkins.assertLogContains(EmperorHasNoClothes.class.getName(), b);
{
// assert the shape of FlowNodes
FlowGraphWalker w = new FlowGraphWalker(b.getExecution());
List<String> nodes = new ArrayList<>();
for (FlowNode n : w) {
String s = n.getClass().getSimpleName();
if (n instanceof StepNode) {
StepNode sn = (StepNode) n;
s += ":" + sn.getDescriptor().getFunctionName();
}
if (n instanceof StepEndNode) {
// this should have recorded a failure
ErrorAction e = n.getAction(ErrorAction.class);
assertEquals(EmperorHasNoClothes.class, e.getError().getClass());
}
nodes.add(s);
}
assertEquals(Arrays.asList("FlowEndNode", // this for the end of invoking a body
"StepEndNode:synchronousExceptionInBody", // this for invoking a body
"StepStartNode:synchronousExceptionInBody", // letting steps take over the FlowNode creation that should solve this.
"StepAtomNode:synchronousExceptionInBody", "FlowStartNode"), nodes);
}
}
use of org.jenkinsci.plugins.workflow.graph.FlowGraphWalker in project workflow-cps-plugin by jenkinsci.
the class CpsScmFlowDefinitionTest method basics.
@Test
public void basics() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
CpsScmFlowDefinition def = new CpsScmFlowDefinition(new SingleFileSCM("flow.groovy", "echo 'hello from SCM'"), "flow.groovy");
// currently the default, but just to be clear that we do rely on that in this test
def.setLightweight(false);
p.setDefinition(def);
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
// TODO currently the log text is in Run.log, but not on FlowStartNode/LogAction, so not visible from Workflow Steps etc.
r.assertLogContains("hello from SCM", b);
r.assertLogContains("Staging flow.groovy", b);
r.assertLogNotContains("Retrying after 10 seconds", b);
FlowGraphWalker w = new FlowGraphWalker(b.getExecution());
int workspaces = 0;
for (FlowNode n : w) {
if (n.getAction(WorkspaceAction.class) != null) {
workspaces++;
}
}
assertEquals(1, workspaces);
}
use of org.jenkinsci.plugins.workflow.graph.FlowGraphWalker in project workflow-job-plugin by jenkinsci.
the class FlowGraphAction method getNodes.
@Exported
public Collection<? extends FlowNode> getNodes() {
FlowExecution exec = run.getExecution();
if (exec == null) {
return Collections.emptySet();
}
List<FlowNode> nodes = new ArrayList<>();
FlowGraphWalker walker = new FlowGraphWalker(exec);
for (FlowNode n : walker) {
nodes.add(n);
}
Collections.reverse(nodes);
return nodes;
}
use of org.jenkinsci.plugins.workflow.graph.FlowGraphWalker in project workflow-job-plugin by jenkinsci.
the class GraphVizAction method writeDot.
private void writeDot(PrintWriter w) throws IOException {
try {
w.println("digraph G {");
FlowGraphWalker walker = new FlowGraphWalker(run.getExecution());
for (FlowNode n : walker) {
for (FlowNode p : n.getParents()) {
w.printf("%s -> %s%n", p.getId(), n.getId());
}
if (n instanceof BlockStartNode) {
BlockStartNode sn = (BlockStartNode) n;
w.printf("%s [shape=trapezium]%n", n.getId());
} else if (n instanceof BlockEndNode) {
BlockEndNode sn = (BlockEndNode) n;
w.printf("%s [shape=invtrapezium]%n", n.getId());
w.printf("%s -> %s [style=dotted]%n", sn.getStartNode().getId(), n.getId());
}
w.printf("%s [label=\"%s: %s\"]%n", n.getId(), n.getId(), n.getDisplayName());
}
w.println("}");
} finally {
w.close();
}
}
Aggregations