Search in sources :

Example 61 with WorkflowJob

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

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

Example 63 with WorkflowJob

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

the class PipelineNodeTest method getPipelineJobRunStepLogTest.

@Test
public void getPipelineJobRunStepLogTest() 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);
    NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
    List<FlowNode> flowNodes = getAllSteps(b1);
    Map resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + flowNodes.get(0).getId() + "/");
    String linkToLog = getActionLink(resp, "org.jenkinsci.plugins.workflow.actions.LogAction");
    assertNotNull(linkToLog);
    assertEquals("/blue/rest/organizations/jenkins/pipelines/pipeline1/runs/1/steps/6/log/", linkToLog);
    String output = get(linkToLog.substring("/blue/rest".length()), String.class);
    Assert.assertNotNull(output);
}
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) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 64 with WorkflowJob

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

the class PipelineNodeTest method KyotoNodesFailureTest3.

@Test
public void KyotoNodesFailureTest3() 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 \"Testing\"'\n" + "}\n" + "        }\n" + "        stage ('Deploy') {\n" + "steps{\n" + "            sh 'echo1 \"Deploying\"'\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("SUCCESS", nodes.get(1).get("result"));
    Assert.assertEquals("FINISHED", nodes.get(1).get("state"));
    Assert.assertEquals("FAILURE", nodes.get(2).get("result"));
    Assert.assertEquals("FINISHED", nodes.get(2).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 65 with WorkflowJob

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

the class PipelineNodeTest method pipelineLogError1.

@Test
public void pipelineLogError1() throws Exception {
    String script = "node {\n" + "    stage('blah') {\n" + "        sh \"echo 42\"\n" + "        error(\"this error should appear in log\")\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/8/log/", String.class);
    Assert.assertTrue(resp.trim().endsWith("this error should appear in log"));
}
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)

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