Search in sources :

Example 6 with NodeStepTypePredicate

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));
}
Also used : ArgumentsAction(org.jenkinsci.plugins.workflow.actions.ArgumentsAction) NodeStepTypePredicate(org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) LinearScanner(org.jenkinsci.plugins.workflow.graphanalysis.LinearScanner) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 7 with NodeStepTypePredicate

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());
}
Also used : ArgumentsAction(org.jenkinsci.plugins.workflow.actions.ArgumentsAction) NodeStepTypePredicate(org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ArrayList(java.util.ArrayList) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) LinearScanner(org.jenkinsci.plugins.workflow.graphanalysis.LinearScanner) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 8 with NodeStepTypePredicate

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());
        }
    }
}
Also used : NodeStepTypePredicate(org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) LinearScanner(org.jenkinsci.plugins.workflow.graphanalysis.LinearScanner) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 9 with NodeStepTypePredicate

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);
}
Also used : NodeStepTypePredicate(org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ConfigFileBuildWrapper(org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) NodeStepTypePredicate(org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Aggregations

CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)9 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)9 NodeStepTypePredicate (org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate)9 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9 Test (org.junit.Test)9 LinearScanner (org.jenkinsci.plugins.workflow.graphanalysis.LinearScanner)5 Predicate (com.google.common.base.Predicate)4 ConfigFileBuildWrapper (org.jenkinsci.plugins.configfiles.buildwrapper.ConfigFileBuildWrapper)4 ArgumentsAction (org.jenkinsci.plugins.workflow.actions.ArgumentsAction)4 DepthFirstScanner (org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner)4 Issue (org.jvnet.hudson.test.Issue)3 ArtifactArchiver (hudson.tasks.ArtifactArchiver)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1