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)); 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)); 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));
if (execution != null) { previousHadStep = new DepthFirstScanner().findFirstMatch(execution, new NodeStepTypePredicate(step.getDescriptor())) != null;
if (execution != null) { previousHadStep = new DepthFirstScanner().findFirstMatch(execution, new NodeStepTypePredicate(step.getDescriptor())) != null;
@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.ArtifactArchiver('x.xml'))\n" + " }\n" + "}", false)); WorkflowRun b = r.buildAndAssertSuccess(p); List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("step")); assertThat(coreStepNodes, hasSize(1)); assertEquals("archiveArtifacts", coreStepNodes.get(0).getDisplayFunctionName()); assertEquals(r.jenkins.getDescriptor(ArtifactArchiver.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] archiveArtifacts", b); r.assertLogContains("[Pipeline] configFileProvider", b); r.assertLogContains("[Pipeline] // configFileProvider", b); }
@Ignore("TODO ArgumentsAction.getResolvedArguments does not yet handle NotStoredReason sensibly") @Test public void metastepConsoleNotStoredArgument() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); String spaces = StringUtils.repeat(" ", 1025); // cf. ArgumentsAction.MAX_RETAINED_LENGTH 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); }
@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" + " archiveArtifacts 'x.xml'\n" + " }\n" + "}", true)); WorkflowRun b = r.buildAndAssertSuccess(p); List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("step")); assertThat(coreStepNodes, hasSize(1)); assertEquals("archiveArtifacts", coreStepNodes.get(0).getDisplayFunctionName()); assertEquals(r.jenkins.getDescriptor(ArtifactArchiver.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] archiveArtifacts", b); r.assertLogContains("[Pipeline] configFileProvider", b); r.assertLogContains("[Pipeline] // configFileProvider", b); }
@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: 'ArtifactArchiver', artifacts: 'x.xml'])\n" + " }\n" + "}", true)); WorkflowRun b = r.buildAndAssertSuccess(p); List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("step")); assertThat(coreStepNodes, hasSize(1)); assertEquals("archiveArtifacts", coreStepNodes.get(0).getDisplayFunctionName()); assertEquals(r.jenkins.getDescriptor(ArtifactArchiver.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] archiveArtifacts", b); r.assertLogContains("[Pipeline] configFileProvider", b); r.assertLogContains("[Pipeline] // configFileProvider", b); }
@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" + " step(new hudson.tasks.ArtifactArchiver('msg.out'))\n" + // note, not whitelisted "}", 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"); // Test that for a raw Describable we explode it into its arguments Map Assert.assertThat(delegate, instanceOf(UninstantiatedDescribable.class)); UninstantiatedDescribable ud = (UninstantiatedDescribable)delegate; Map<String, ?> args = (Map<String,?>)(((UninstantiatedDescribable)delegate).getArguments()); Assert.assertThat(args, IsMapContaining.hasEntry("artifacts", "msg.out")); Assert.assertEquals(ArtifactArchiver.class.getName(), ud.getModel().getType().getName()); } }
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("msg.out", act.getArgumentValue("file")); testNode = scan.findFirstMatch(run.getExecution().getCurrentHeads().get(0), new NodeStepTypePredicate("step")); act = testNode.getPersistentAction(ArgumentsAction.class); Assert.assertNotNull(act);
/** * 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)); }
@Test @Issue("JENKINS-48644") public void testMissingDescriptionInsideStage() throws Exception { Assume.assumeTrue(r.jenkins.getComputer("").isUnix()); // No need for windows-specific testing 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()); } } }