Search in sources :

Example 71 with WorkflowRun

use of org.jenkinsci.plugins.workflow.job.WorkflowRun 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 72 with WorkflowRun

use of org.jenkinsci.plugins.workflow.job.WorkflowRun 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 73 with WorkflowRun

use of org.jenkinsci.plugins.workflow.job.WorkflowRun 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)

Example 74 with WorkflowRun

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

the class PipelineNodeTest method stepStatusForFailedBuild.

@Test
@Issue("JENKINS-39296")
public void stepStatusForFailedBuild() throws Exception {
    String p = "node {\n" + "   echo 'Hello World'\n" + "   try{\n" + "    echo 'Inside try'\n" + "    sh 'this should fail'" + "   }finally{\n" + "    echo 'this should pass'\n" + "   }\n" + "}";
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition(p));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.FAILURE, b1);
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
    Assert.assertEquals(resp.size(), 4);
    Map helloWorldStep = resp.get(0);
    Assert.assertEquals("Hello World", helloWorldStep.get("displayDescription"));
    Assert.assertEquals("SUCCESS", helloWorldStep.get("result"));
    Assert.assertEquals("FINISHED", helloWorldStep.get("state"));
    Map insideTryStep = resp.get(1);
    Assert.assertEquals("Inside try", insideTryStep.get("displayDescription"));
    Assert.assertEquals("SUCCESS", insideTryStep.get("result"));
    Assert.assertEquals("FINISHED", insideTryStep.get("state"));
    Map thisShouldFailStep = resp.get(2);
    Assert.assertEquals("this should fail", thisShouldFailStep.get("displayDescription"));
    Assert.assertEquals("FAILURE", thisShouldFailStep.get("result"));
    Assert.assertEquals("FINISHED", thisShouldFailStep.get("state"));
    Map thisShouldPassStep = resp.get(3);
    Assert.assertEquals("this should pass", thisShouldPassStep.get("displayDescription"));
    Assert.assertEquals("SUCCESS", thisShouldPassStep.get("result"));
    Assert.assertEquals("FINISHED", thisShouldPassStep.get("state"));
}
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) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 75 with WorkflowRun

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

the class PipelineNodeTest method submitInput.

@Test
public void submitInput() throws Exception {
    String script = "node {\n" + "    stage(\"first\"){\n" + "            def branchInput = input message: 'Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + "            echo \"BRANCH NAME: ${branchInput}\"\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);
    Assert.assertEquals("PAUSED", stepsResp.get(0).get("state"));
    Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result"));
    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);
    List<Map<String, Object>> params = (List<Map<String, Object>>) input.get("parameters");
    post("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/7/", ImmutableMap.of("id", id, PARAMETERS_ELEMENT, ImmutableList.of(ImmutableMap.of("name", params.get(0).get("name"), "value", "master"))), 200);
    if (waitForBuildCount(job1, 1, Result.SUCCESS)) {
        Map<String, Object> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/7/");
        Assert.assertEquals("FINISHED", resp.get("state"));
        Assert.assertEquals("SUCCESS", resp.get("result"));
        Assert.assertEquals("7", resp.get("id"));
    }
}
Also used : InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) JSONObject(net.sf.json.JSONObject) 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) Test(org.junit.Test)

Aggregations

WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)77 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)72 Test (org.junit.Test)70 Map (java.util.Map)58 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)53 ImmutableMap (com.google.common.collect.ImmutableMap)45 List (java.util.List)22 ImmutableList (com.google.common.collect.ImmutableList)20 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)19 RunList (hudson.util.RunList)18 BranchSource (jenkins.branch.BranchSource)12 GitSCMSource (jenkins.plugins.git.GitSCMSource)12 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)12 SCMSource (jenkins.scm.api.SCMSource)11 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)8 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)7 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)6 Issue (org.jvnet.hudson.test.Issue)6 Run (hudson.model.Run)4 JSONObject (net.sf.json.JSONObject)4