Search in sources :

Example 51 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 52 with WorkflowRun

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

the class PipelineApiTest method getPipelineJobAbortTest.

@Test
public void getPipelineJobAbortTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   sh('sleep 60') " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    for (int i = 0; i < 10; i++) {
        b1.doStop();
        if (b1.getResult() != null) {
            break;
        }
        Thread.sleep(1000);
    }
    j.assertBuildStatus(Result.ABORTED, b1);
    Map r = get("/organizations/jenkins/pipelines/pipeline1/runs/1");
    validateRun(b1, r);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 53 with WorkflowRun

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

the class PipelineNodeTest method KyotoNodesFailureTest2.

@Test
public void KyotoNodesFailureTest2() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("pipeline {\n" + "    agent any\n" + "    stages {\n" + "        stage ('Build') {\n" + "steps{\n" + "            sh 'echo \"Building\"'\n" + "}\n" + "        }\n" + "        stage ('Test') {\n" + "steps{\n" + "            sh 'echo \"Building\"'\n" + "            sh 'echo2 \"Building finished\"'\n" + "}\n" + "        }\n" + "        stage ('Deploy') {\n" + "steps{\n" + "            sh 'echo \"Building\"'\n" + "}\n" + "        }\n" + "    }\n" + "}\n"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.FAILURE, b1);
    List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    Assert.assertEquals(3, nodes.size());
    Assert.assertEquals("SUCCESS", nodes.get(0).get("result"));
    Assert.assertEquals("FINISHED", nodes.get(0).get("state"));
    Assert.assertEquals("FAILURE", nodes.get(1).get("result"));
    Assert.assertEquals("FINISHED", nodes.get(1).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) Test(org.junit.Test)

Aggregations

WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)53 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)50 Test (org.junit.Test)47 Map (java.util.Map)45 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)43 ImmutableMap (com.google.common.collect.ImmutableMap)37 List (java.util.List)17 ImmutableList (com.google.common.collect.ImmutableList)16 RunList (hudson.util.RunList)15 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)14 BranchSource (jenkins.branch.BranchSource)7 GitSCMSource (jenkins.plugins.git.GitSCMSource)7 SCMSource (jenkins.scm.api.SCMSource)7 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)7 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)4 JSONObject (net.sf.json.JSONObject)4 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)4 FlowGraphTable (org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable)4 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)3 Queue (hudson.model.Queue)2