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