Search in sources :

Example 46 with WorkflowRun

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

the class PipelineNodeTest method getPipelineWihNodesAllStepsTest.

@Test
public void getPipelineWihNodesAllStepsTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + "  sh \"echo Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + "  node{\n" + "    echo \"Unit testing...\"\n" + "    sh \"echo Tests running\"\n" + "    sh \"echo Tests completed\"\n" + "  }\n" + "},'integration':{\n" + "  node{\n" + "    echo \"Integration testing...\"\n" + "  }\n" + "}, 'ui':{\n" + "  node{\n" + "    echo \"UI testing...\"\n" + "  }\n" + "}\n" + "\n" + "node{\n" + "  echo \"Done Testing\"\n" + "}" + "\n" + "stage 'deploy'\n" + "node{\n" + "  echo \"Deploying\"\n" + "}" + "\n" + "stage 'deployToProd'\n" + "node{\n" + "  echo \"Deploying to production\"\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    FlowGraphTable nodeGraphTable = new FlowGraphTable(b1.getExecution());
    nodeGraphTable.build();
    List<FlowNode> nodes = getStages(nodeGraphTable);
    List<FlowNode> parallelNodes = getParallelNodes(nodeGraphTable);
    Assert.assertEquals(7, nodes.size());
    Assert.assertEquals(3, parallelNodes.size());
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
    Assert.assertEquals(9, resp.size());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FlowGraphTable(org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable) 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 47 with WorkflowRun

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

the class PipelineNodeTest method pipelineLogError.

@Test
public void pipelineLogError() throws Exception {
    String script = "def foo = null\n" + "\n" + "node {\n" + "    stage('blah') {\n" + "        sh \"echo 42\"\n" + "        foo.bar = 42\n" + "        sh \"echo 43\"\n" + "        \n" + "    }\n" + "}";
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition(script));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.FAILURE, b1);
    String resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/7/log", String.class);
    System.out.println(resp);
    Assert.assertTrue(resp.trim().endsWith("Cannot set property 'bar' on null object"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 48 with WorkflowRun

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

the class PipelineNodeTest method stepStatusForFailedBuild.

//JENKINS-39296
@Test
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" + "    sh 'echo \"blah\"' \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);
    for (int i = 0; i < resp.size(); i++) {
        Map rn = resp.get(i);
        if (i == 2) {
            Assert.assertEquals("FAILURE", rn.get("result"));
        } else {
            Assert.assertEquals("SUCCESS", rn.get("result"));
        }
        Assert.assertEquals("FINISHED", rn.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)

Example 49 with WorkflowRun

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

the class PipelineNodeTest method getPipelineJobRunNodeLogTest.

@Test
public void getPipelineJobRunNodeLogTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + "  echo \"Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + "  node{\n" + "    echo \"Unit testing...\"\n" + "  }\n" + "},'integration':{\n" + "  node{\n" + "    echo \"Integration testing...\"\n" + "  }\n" + "}, 'ui':{\n" + "  node{\n" + "    echo \"UI testing...\"\n" + "  }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + "  echo \"Deploying\"\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    FlowGraphTable nodeGraphTable = new FlowGraphTable(b1.getExecution());
    nodeGraphTable.build();
    List<FlowNode> nodes = getStages(nodeGraphTable);
    List<FlowNode> parallelNodes = getParallelNodes(nodeGraphTable);
    Assert.assertEquals(6, nodes.size());
    Assert.assertEquals(3, parallelNodes.size());
    String output = get("/organizations/jenkins/pipelines/pipeline1/runs/1/log", String.class);
    assertNotNull(output);
    System.out.println(output);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FlowGraphTable(org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 50 with WorkflowRun

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

the class PipelineNodeTest method getPipelineStepsTest.

@Test
public void getPipelineStepsTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + "  sh \"echo Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + "  node{\n" + "    echo \"Unit testing...\"\n" + "    sh \"echo Tests running\"\n" + "    sh \"echo Tests completed\"\n" + "  }\n" + "},'integration':{\n" + "  node{\n" + "    echo \"Integration testing...\"\n" + "  }\n" + "}, 'ui':{\n" + "  node{\n" + "    echo \"UI testing...\"\n" + "  }\n" + "}\n" + "\n" + "node{\n" + "  echo \"Done Testing\"\n" + "}" + "\n" + "stage 'deploy'\n" + "node{\n" + "  echo \"Deploying\"\n" + "}" + "\n" + "stage 'deployToProd'\n" + "node{\n" + "  echo \"Deploying to production\"\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    FlowGraphTable nodeGraphTable = new FlowGraphTable(b1.getExecution());
    nodeGraphTable.build();
    List<FlowNode> nodes = getStages(nodeGraphTable);
    List<FlowNode> parallelNodes = getParallelNodes(nodeGraphTable);
    Assert.assertEquals(7, nodes.size());
    Assert.assertEquals(3, parallelNodes.size());
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + nodes.get(1).getId() + "/steps/", List.class);
    Assert.assertEquals(6, resp.size());
    Map step = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + parallelNodes.get(0).getId() + "/steps/" + resp.get(0).get("id"), Map.class);
    assertNotNull(step);
    String stepLog = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + parallelNodes.get(0).getId() + "/steps/" + resp.get(0).get("id") + "/log", String.class);
    assertNotNull(stepLog);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FlowGraphTable(org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable) 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)

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