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);
}
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());
}
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);
}
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"));
}
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"));
}
Aggregations