@Override public boolean setup(@CheckForNull Collection<FlowNode> heads, @CheckForNull Collection<FlowNode> blackList) { boolean possiblyStartable = super.setup(heads, blackList); return possiblyStartable && myCurrent != null; // In case we start at an end block }
LinearScanner scan = new LinearScanner(); 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)); 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());
)); WorkflowRun run = r.buildAndAssertSuccess(job); LinearScanner scan = new LinearScanner(); FlowNode node = scan.findFirstMatch(run.getExecution(), new DescriptorMatchPredicate(StateMetaStep.DescriptorImpl.class)); Assert.assertNotNull(node); Map<String,Object> args = ArgumentsAction.getArguments(node); )); run = r.buildAndAssertSuccess(job); List<FlowNode> nodes = scan.filteredNodes(run.getExecution(), new DescriptorMatchPredicate(StateMetaStep.DescriptorImpl.class)); for (FlowNode n : nodes) { Assert.assertNotNull(n);
@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()); } } }
@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()); } }
)); 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("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)); }