Search in sources :

Example 91 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method testTestsInStage.

@Test
public void testTestsInStage() throws Exception {
    String pipeline = "" + "node {\n" + "  stage ('dev') {\n" + "    junit('*.xml')\n" + "  }\n" + "  stage ('prod') {\n" + "    junit('*.xml')\n" + "  }\n" + "  stage ('testing') {\n" + "    parallel(first: {\n" + "        junit('*.xml')\n" + "      },\n" + "      second: {\n" + "        junit('*.xml')\n" + "      })\n" + "  }\n" + "}\n";
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition(pipeline, true));
    FilePath ws = j.jenkins.getWorkspaceFor(job1);
    FilePath testFile = ws.child("test-result.xml");
    testFile.copyFrom(PipelineNodeTest.class.getResource("testResult.xml"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
    List<FlowNode> stages = getStages(builder);
    Assert.assertEquals(3, stages.size());
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    Assert.assertEquals(5, resp.size());
    resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/tests/", List.class);
    Assert.assertEquals(4, resp.size());
    Assert.assertEquals("dev / testDummyMethod – DummyTest", resp.get(0).get("name"));
    Assert.assertEquals("prod / testDummyMethod – DummyTest", resp.get(1).get("name"));
    Assert.assertEquals("testing / first / testDummyMethod – DummyTest", resp.get(2).get("name"));
    Assert.assertEquals("testing / second / testDummyMethod – DummyTest", resp.get(3).get("name"));
}
Also used : FilePath(hudson.FilePath) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) RunList(hudson.util.RunList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 92 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method testDynamicInnerStage.

@Test
public void testDynamicInnerStage() throws Exception {
    WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "p");
    URL resource = Resources.getResource(getClass(), "testDynamicInnerStage.jenkinsfile");
    String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
    job.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
    WorkflowRun build = job.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.SUCCESS, build);
    List<Map> nodes = get("/organizations/jenkins/pipelines/p/runs/1/nodes/", List.class);
    assertEquals(4, nodes.size());
    assertEquals(FlowNodeWrapper.NodeType.STAGE.name(), nodes.get(0).get("type"));
    assertEquals(FlowNodeWrapper.NodeType.STAGE.name(), nodes.get(1).get("type"));
    assertEquals(FlowNodeWrapper.NodeType.PARALLEL.name(), nodes.get(2).get("type"));
    assertEquals(FlowNodeWrapper.NodeType.STAGE.name(), nodes.get(3).get("type"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) URL(java.net.URL) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 93 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method testBlockedStep.

@Test
public void testBlockedStep() throws Exception {
    String scipt = "node {\n" + "    stage(\"one\"){\n" + "        echo '1'\n" + "    }\n" + "    stage(\"two\") {\n" + "            node('blah'){\n" + "                sh 'blah'\n" + "            }\n" + "        }\n" + "\n" + "}";
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition(scipt, false));
    QueueTaskFuture<WorkflowRun> runQueueTaskFuture = job1.scheduleBuild2(0);
    WorkflowRun run = runQueueTaskFuture.getStartCondition().get();
    CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
    if (waitForItemToAppearInQueue(1000 * 300)) {
        // 5 min timeout
        List<FlowNode> nodes = getStages(NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run));
        if (nodes.size() == 2) {
            List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/11/steps/", List.class);
            assertEquals(1, stepsResp.size());
            assertEquals("QUEUED", stepsResp.get(0).get("state"));
        }
    } else {
        // Avoid spurious code coverage failures
        final FlowNode node = new FlowNode(null, "fake") {

            @Override
            protected String getTypeDisplayName() {
                return "fake";
            }
        };
        final MemoryFlowChunk chunk = new MemoryFlowChunk() {

            @Override
            public FlowNode getFirstNode() {
                return node;
            }
        };
        new PipelineStepVisitor.LocalAtomNode(chunk, "fake");
    }
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) MemoryFlowChunk(org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 94 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method stepStatusForUnstableBuild.

// JENKINS-39203
@Test
public void stepStatusForUnstableBuild() throws Exception {
    String p = "node {\n" + "   echo 'Hello World'\n" + "   try{\n" + "    echo 'Inside try'\n" + "   }finally{\n" + "    sh 'echo \"blah\"' \n" + "    currentBuild.result = \"UNSTABLE\"\n" + "   }\n" + "}";
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition(p));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.UNSTABLE, b1);
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
    Assert.assertEquals(resp.size(), 3);
    for (int i = 0; i < resp.size(); i++) {
        Map rn = resp.get(i);
        Assert.assertEquals(rn.get("result"), "SUCCESS");
        Assert.assertEquals(rn.get("state"), "FINISHED");
    }
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 95 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method abortInput.

@Test
public void abortInput() throws Exception {
    String script = "node {\n" + "    stage(\"thing\"){\n" + "            input 'continue'\n" + "    }\n" + "}";
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition(script));
    QueueTaskFuture<WorkflowRun> buildTask = job1.scheduleBuild2(0);
    WorkflowRun run = buildTask.getStartCondition().get();
    CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
    while (run.getAction(InputAction.class) == null) {
        e.waitForSuspension();
    }
    List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
    System.out.println(stepsResp);
    Assert.assertEquals("PAUSED", stepsResp.get(0).get("state"));
    Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result"));
    String stepId = (String) stepsResp.get(0).get("id");
    // Assert.assertEquals("7", stepsResp.get(0).get("id"));
    Map<String, Object> input = (Map<String, Object>) stepsResp.get(0).get("input");
    Assert.assertNotNull(input);
    String id = (String) input.get("id");
    Assert.assertNotNull(id);
    JSONObject req = new JSONObject();
    req.put("id", id);
    req.put("abort", true);
    post("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + stepId + "/", req, 200);
    if (waitForBuildCount(job1, 1, Result.ABORTED)) {
        Map<String, Object> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + stepId + "/");
        Assert.assertEquals("FINISHED", resp.get("state"));
        Assert.assertEquals("ABORTED", resp.get("result"));
        Assert.assertEquals(stepId, resp.get("id"));
    }
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) JSONObject(net.sf.json.JSONObject) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) JSONObject(net.sf.json.JSONObject) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) Test(org.junit.Test)

Aggregations

WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)100 Test (org.junit.Test)91 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)74 Map (java.util.Map)73 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)62 ImmutableMap (com.google.common.collect.ImmutableMap)55 List (java.util.List)34 ImmutableList (com.google.common.collect.ImmutableList)28 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)26 BranchSource (jenkins.branch.BranchSource)24 GitSCMSource (jenkins.plugins.git.GitSCMSource)24 SCMSource (jenkins.scm.api.SCMSource)23 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)20 RunList (hudson.util.RunList)19 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)17 ArrayList (java.util.ArrayList)10 URL (java.net.URL)9 Run (hudson.model.Run)8 Issue (org.jvnet.hudson.test.Issue)8 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)7