use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate in project workflow-cps-plugin by jenkinsci.
the class ArgumentsActionImplTest method testReallyUnusualStepInstantiations.
@Test
public void testReallyUnusualStepInstantiations() throws Exception {
WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "unusualInstantiation");
job.setDefinition(new CpsFlowDefinition(" node() {\n" + " writeFile text: 'hello world', file: 'msg.out'\n" + // note, not whitelisted
" step(new hudson.tasks.ArtifactArchiver('msg.out'))\n" + "}", false));
WorkflowRun run = r.buildAndAssertSuccess(job);
LinearScanner scan = new LinearScanner();
FlowNode testNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), new NodeStepTypePredicate("step"));
ArgumentsAction act = testNode.getPersistentAction(ArgumentsAction.class);
Assert.assertNotNull(act);
Object delegate = act.getArgumentValue("delegate");
Assert.assertThat(delegate, instanceOf(ArtifactArchiver.class));
Assert.assertEquals("msg.out", ((ArtifactArchiver) delegate).getArtifacts());
Assert.assertFalse(((ArtifactArchiver) delegate).isFingerprint());
}
use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate in project workflow-cps-plugin by jenkinsci.
the class ArgumentsActionImplTest method testArgumentDescriptions.
@Test
public void testArgumentDescriptions() throws Exception {
WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "argumentDescription");
job.setDefinition(new CpsFlowDefinition("echo 'test' \n " + " node('master') { \n" + " retry(3) {\n" + " if (isUnix()) { \n" + " sh 'whoami' \n" + " } else { \n" + " bat 'echo %USERNAME%' \n" + " }\n" + " } \n" + "}"));
WorkflowRun run = r.buildAndAssertSuccess(job);
LinearScanner scan = new LinearScanner();
// Argument test
FlowNode echoNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), new NodeStepTypePredicate("echo"));
Assert.assertEquals("test", echoNode.getPersistentAction(ArgumentsAction.class).getArguments().values().iterator().next());
Assert.assertEquals("test", ArgumentsAction.getStepArgumentsAsString(echoNode));
if (Functions.isWindows()) {
FlowNode batchNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), new NodeStepTypePredicate("bat"));
Assert.assertEquals("echo %USERNAME%", batchNode.getPersistentAction(ArgumentsAction.class).getArguments().values().iterator().next());
Assert.assertEquals("echo %USERNAME%", ArgumentsAction.getStepArgumentsAsString(batchNode));
} else {
// Unix
FlowNode shellNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), new NodeStepTypePredicate("sh"));
Assert.assertEquals("whoami", shellNode.getPersistentAction(ArgumentsAction.class).getArguments().values().iterator().next());
Assert.assertEquals("whoami", ArgumentsAction.getStepArgumentsAsString(shellNode));
}
FlowNode nodeNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), Predicates.and(Predicates.instanceOf(StepStartNode.class), new NodeStepTypePredicate("node"), FlowScanningUtils.hasActionPredicate(ArgumentsActionImpl.class)));
Assert.assertEquals("master", nodeNode.getPersistentAction(ArgumentsAction.class).getArguments().values().iterator().next());
Assert.assertEquals("master", ArgumentsAction.getStepArgumentsAsString(nodeNode));
testDeserialize(run.getExecution());
}
use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate in project workflow-cps-plugin by jenkinsci.
the class StepNodeTest method metastepConsoleNotStoredArgument.
@Ignore("TODO ArgumentsAction.getResolvedArguments does not yet handle NotStoredReason sensibly")
@Test
public void metastepConsoleNotStoredArgument() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
// cf. ArgumentsAction.MAX_RETAINED_LENGTH
String spaces = StringUtils.repeat(" ", 1025);
p.setDefinition(new CpsFlowDefinition("node {\n" + " configFileProvider([]) {\n" + " writeFile text: '''<testsuite name='a'><testcase name='c'><error>failed</error></testcase></testsuite>''', file: 'x.xml'\n" + " junit 'x.xml," + spaces + "'\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);
}
use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate in project workflow-cps-plugin by jenkinsci.
the class StepNodeTest method metastepConsoleRaw.
@Test
public void metastepConsoleRaw() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {\n" + " wrap(new org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper([])) {\n" + " writeFile text: '''<testsuite name='a'><testcase name='c'><error>failed</error></testcase></testsuite>''', file: 'x.xml'\n" + " step(new hudson.tasks.junit.JUnitResultArchiver('x.xml'))\n" + " }\n" + "}", false));
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);
}
use of org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate in project workflow-cps-plugin by jenkinsci.
the class StepNodeTest method metastepConsole.
@Issue("JENKINS-45109")
@Test
public void metastepConsole() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {\n" + " configFileProvider([]) {\n" + " writeFile text: '''<testsuite name='a'><testcase name='c'><error>failed</error></testcase></testsuite>''', file: 'x.xml'\n" + " junit '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