Search in sources :

Example 41 with WorkflowRun

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

the class PipelineNodeTest method countBuilds.

private static int countBuilds(WorkflowJob job, Result status) {
    RunList<WorkflowRun> builds = job.getNewBuilds();
    Iterator<WorkflowRun> iterator = builds.iterator();
    int numBuilds = 0;
    while (iterator.hasNext()) {
        WorkflowRun build = iterator.next();
        Result buildRes = build.getResult();
        if (status == null || buildRes == status) {
            numBuilds++;
        }
    }
    return numBuilds;
}
Also used : WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Result(hudson.model.Result)

Example 42 with WorkflowRun

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

the class PipelineNodeTest method stageTestJENKINS_40135.

@Test
public void stageTestJENKINS_40135() throws Exception {
    String script = "node {\n" + "    stage 'Stage 1'\n" + "    stage 'Stage 2'\n" + "       echo 'hello'\n" + "}";
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition(script));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    Assert.assertEquals(2, nodes.size());
    Assert.assertEquals("SUCCESS", nodes.get(0).get("result"));
    Assert.assertEquals("FINISHED", nodes.get(0).get("state"));
    Assert.assertEquals("SUCCESS", 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)

Example 43 with WorkflowRun

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

the class PipelineApiTest method getPipelineJobRunsTest.

@Test
public void getPipelineJobRunsTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   echo ('Building'); " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    WorkflowRun b2 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b2);
    Run[] runs = { b2, b1 };
    List<Map> runResponses = get("/organizations/jenkins/pipelines/pipeline1/runs", List.class);
    for (int i = 0; i < runs.length; i++) {
        validateRun(runs[i], runResponses.get(i));
    }
    ;
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Run(hudson.model.Run) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 44 with WorkflowRun

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

the class PipelineApiTest method getPipelineJobRunsLogTest.

@Test
public void getPipelineJobRunsLogTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   echo ('Building'); " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    HttpResponse<String> response = get("/organizations/jenkins/pipelines/pipeline1/runs/" + b1.getId() + "/log?start=0", 200, "text/html", HttpResponse.class);
    AcceptHeader acceptHeader = new AcceptHeader(response.getHeaders().getFirst("Content-Type"));
    Assert.assertNotNull(acceptHeader.select("text/plain"));
    int size = Integer.parseInt(response.getHeaders().getFirst("X-Text-Size"));
    System.out.println(response.getBody());
    Assert.assertTrue(size > 0);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) AcceptHeader(org.kohsuke.stapler.AcceptHeader) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 45 with WorkflowRun

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

the class PipelineNodeTest method nodesWithPartialParallels.

@Test
public void nodesWithPartialParallels() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("node {\n" + "    stage \"hey\"\n" + "    sh \"echo yeah\"\n" + "    \n" + "    stage \"par\"\n" + "    \n" + "    parallel left : {\n" + "            sh \"echo OMG BS\"\n" + "            sh \"echo yeah\"\n" + "        }, \n" + "        \n" + "        right : {\n" + "            sh \"echo wozzle\"\n" + "        }\n" + "    \n" + "    stage \"ho\"\n" + "        sh \"echo done\"\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    Thread.sleep(1000);
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    Assert.assertEquals(5, resp.size());
    job1.setDefinition(new CpsFlowDefinition("node {\n" + "    stage \"hey\"\n" + "    sh \"echo yeah\"\n" + "    \n" + "    stage \"par\"\n" + "    \n" + "    parallel left : {\n" + "            sh \"echo OMG BS\"\n" + "            echo \"running\"\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" + "            sh \"echo yeah\"\n" + "        }, \n" + "        \n" + "        right : {\n" + "            sh \"echo wozzle\"\n" + "            def branchInput = input message: 'MF Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + "            echo \"BRANCH NAME: ${branchInput}\"\n" + "        }\n" + "    \n" + "    stage \"ho\"\n" + "        sh \"echo done\"\n" + "}"));
    job1.scheduleBuild2(0);
    Thread.sleep(1000);
    resp = get("/organizations/jenkins/pipelines/pipeline1/runs/2/nodes/", List.class);
    Assert.assertEquals(5, resp.size());
    Map leftNode = resp.get(2);
    Assert.assertEquals("left", leftNode.get("displayName"));
    Map rightNode = resp.get(3);
    Assert.assertEquals("right", rightNode.get("displayName"));
    List<Map> leftSteps = get("/organizations/jenkins/pipelines/pipeline1/runs/2/nodes/" + leftNode.get("id") + "/steps/", List.class);
    Assert.assertEquals(3, leftSteps.size());
    List<Map> rightSteps = get("/organizations/jenkins/pipelines/pipeline1/runs/2/nodes/" + rightNode.get("id") + "/steps/", List.class);
    Assert.assertEquals(2, rightSteps.size());
}
Also used : 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) 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