use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate in project workflow-cps-plugin by jenkinsci.
the class DSLTest method monomorphic.
/**
* Tests the ability to execute a step with an unnamed monomorphic describable argument.
*/
@Issue("JENKINS-29711")
@Test
public void monomorphic() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "mon");
p.setDefinition(new CpsFlowDefinition("monomorphStep([firstArg:'one', secondArg:'two'])", true));
r.assertLogContains("First arg: one, second arg: two", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
WorkflowRun run = p.getLastBuild();
LinearScanner scanner = new LinearScanner();
FlowNode node = scanner.findFirstMatch(run.getExecution().getCurrentHeads(), new NodeStepTypePredicate("monomorphStep"));
ArgumentsAction argumentsAction = node.getPersistentAction(ArgumentsAction.class);
Assert.assertNotNull(argumentsAction);
Assert.assertEquals("one,two", ArgumentsAction.getStepArgumentsAsString(node));
}
use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate in project workflow-cps-plugin by jenkinsci.
the class ArgumentsActionImplTest method testUnusualStepInstantiations.
@Test
public void testUnusualStepInstantiations() throws Exception {
WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "unusualInstantiation");
job.setDefinition(new CpsFlowDefinition(" node('master') { \n" + " writeFile text: 'hello world', file: 'msg.out'\n" + " step([$class: 'ArtifactArchiver', artifacts: 'msg.out', fingerprint: false])\n " + // Symbol-based, because withEnv is a metastep; TODO huh? no it is not
" withEnv(['CUSTOM=val']) {\n" + " echo env.CUSTOM\n" + " }\n" + "}"));
WorkflowRun run = r.buildAndAssertSuccess(job);
LinearScanner scan = new LinearScanner();
FlowNode testNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), new NodeStepTypePredicate("writeFile"));
ArgumentsAction act = testNode.getPersistentAction(ArgumentsAction.class);
Assert.assertNotNull(act);
Assert.assertEquals("hello world", act.getArgumentValue("text"));
Assert.assertEquals("msg.out", act.getArgumentValue("file"));
testNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), new NodeStepTypePredicate("step"));
act = testNode.getPersistentAction(ArgumentsAction.class);
Assert.assertNotNull(act);
Map<String, Object> delegateMap = ((Map<String, Object>) act.getArgumentValue("delegate"));
Assert.assertEquals("msg.out", delegateMap.get("artifacts"));
Assert.assertEquals(Boolean.FALSE, delegateMap.get("fingerprint"));
// Start node for EnvAction
testNode = run.getExecution().getNode("7");
act = testNode.getPersistentAction(ArgumentsAction.class);
Assert.assertNotNull(act);
Assert.assertEquals(1, act.getArguments().size());
Object ob = act.getArguments().get("overrides");
Assert.assertEquals("CUSTOM=val", (String) ((ArrayList) ob).get(0));
testDeserialize(run.getExecution());
}
use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate in project workflow-cps-plugin by jenkinsci.
the class ArgumentsActionImplTest method testMissingDescriptionInsideStage.
@Test
@Issue("JENKINS-48644")
public void testMissingDescriptionInsideStage() throws Exception {
// No need for windows-specific testing
Assume.assumeTrue(r.jenkins.getComputer("").isUnix());
WorkflowJob j = r.jenkins.createProject(WorkflowJob.class, "HiddenStep");
j.setDefinition(new CpsFlowDefinition("node{\n" + " stage ('Build') {\n" + " sh \"echo 'Building'\"\n" + " }\n" + " stage ('Test') {\n" + " sh \"echo 'testing'\"\n" + " }\n" + " stage ('Deploy') {\n" + " sh \"echo 'deploy'\"\n" + " }\n" + "}\n", true));
WorkflowRun run = r.buildAndAssertSuccess(j);
List<FlowNode> nodes = new LinearScanner().filteredNodes(run.getExecution(), new NodeStepTypePredicate("sh"));
for (FlowNode f : nodes) {
if (ArgumentsAction.getStepArgumentsAsString(f) == null) {
Assert.fail("No arguments action for node: " + f.toString());
}
}
}
use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate in project workflow-cps-plugin by jenkinsci.
the class StepNodeTest method metastepConsoleShellClass.
@Test
public void metastepConsoleShellClass() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {\n" + " wrap([$class: 'ConfigFileBuildWrapper', managedFiles: []]) {\n" + " writeFile text: '''<testsuite name='a'><testcase name='c'><error>failed</error></testcase></testsuite>''', file: 'x.xml'\n" + " step([$class: 'JUnitResultArchiver', testResults: 'x.xml'])\n" + " }\n" + "}", true));
WorkflowRun b = r.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0));
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("step"));
assertThat(coreStepNodes, hasSize(1));
assertEquals("junit", coreStepNodes.get(0).getDisplayFunctionName());
assertEquals(r.jenkins.getDescriptor(JUnitResultArchiver.class).getDisplayName(), coreStepNodes.get(0).getDisplayName());
List<FlowNode> coreWrapperStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), Predicates.and(new NodeStepTypePredicate("wrap"), new Predicate<FlowNode>() {
@Override
public boolean apply(FlowNode n) {
return n instanceof StepStartNode && !((StepStartNode) n).isBody();
}
}));
assertThat(coreWrapperStepNodes, hasSize(1));
assertEquals("configFileProvider", coreWrapperStepNodes.get(0).getDisplayFunctionName());
assertEquals(r.jenkins.getDescriptor(ConfigFileBuildWrapper.class).getDisplayName() + " : Start", coreWrapperStepNodes.get(0).getDisplayName());
r.assertLogContains("[Pipeline] junit", b);
r.assertLogContains("[Pipeline] configFileProvider", b);
r.assertLogContains("[Pipeline] // configFileProvider", b);
}
Aggregations