use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method stepStatusForFailedBuild.
@Test
@Issue("JENKINS-39296")
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" + " echo 'this should pass'\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);
Map helloWorldStep = resp.get(0);
Assert.assertEquals("Hello World", helloWorldStep.get("displayDescription"));
Assert.assertEquals("SUCCESS", helloWorldStep.get("result"));
Assert.assertEquals("FINISHED", helloWorldStep.get("state"));
Map insideTryStep = resp.get(1);
Assert.assertEquals("Inside try", insideTryStep.get("displayDescription"));
Assert.assertEquals("SUCCESS", insideTryStep.get("result"));
Assert.assertEquals("FINISHED", insideTryStep.get("state"));
Map thisShouldFailStep = resp.get(2);
Assert.assertEquals("this should fail", thisShouldFailStep.get("displayDescription"));
Assert.assertEquals("FAILURE", thisShouldFailStep.get("result"));
Assert.assertEquals("FINISHED", thisShouldFailStep.get("state"));
Map thisShouldPassStep = resp.get(3);
Assert.assertEquals("this should pass", thisShouldPassStep.get("displayDescription"));
Assert.assertEquals("SUCCESS", thisShouldPassStep.get("result"));
Assert.assertEquals("FINISHED", thisShouldPassStep.get("state"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method submitInput.
@Test
public void submitInput() throws Exception {
String script = "node {\n" + " stage(\"first\"){\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" + " }\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script));
QueueTaskFuture<WorkflowRun> buildTask = job1.scheduleBuild2(0);
WorkflowRun run = buildTask.getStartCondition().get();
CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
while (run.getAction(InputAction.class) == null) {
e.waitForSuspension();
}
List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals("PAUSED", stepsResp.get(0).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result"));
Assert.assertEquals("7", stepsResp.get(0).get("id"));
Map<String, Object> input = (Map<String, Object>) stepsResp.get(0).get("input");
Assert.assertNotNull(input);
String id = (String) input.get("id");
Assert.assertNotNull(id);
List<Map<String, Object>> params = (List<Map<String, Object>>) input.get("parameters");
post("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/7/", ImmutableMap.of("id", id, PARAMETERS_ELEMENT, ImmutableList.of(ImmutableMap.of("name", params.get(0).get("name"), "value", "master"))), 200);
if (waitForBuildCount(job1, 1, Result.SUCCESS)) {
Map<String, Object> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/7/");
Assert.assertEquals("FINISHED", resp.get("state"));
Assert.assertEquals("SUCCESS", resp.get("result"));
Assert.assertEquals("7", resp.get("id"));
}
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class StageDurationTrendApiTest method getDurationTrend.
@Test
public void getDurationTrend() throws Exception {
URL resource = Resources.getResource(getClass(), "declarativeThreeStages.jenkinsfile");
String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
WorkflowJob p = j.createProject(WorkflowJob.class, "duration-trend");
p.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
p.save();
Run r = p.scheduleBuild2(0).waitForStart();
j.waitForCompletion(r);
Map response = new RequestBuilder(baseUrl).get("/organizations/jenkins/pipelines/" + p.getName() + "/trends/stageDuration/").build(Map.class);
Assert.assertNotNull(response);
List rows = new RequestBuilder(baseUrl).get("/organizations/jenkins/pipelines/" + p.getName() + "/trends/stageDuration/rows/").build(List.class);
Assert.assertNotNull(rows);
Assert.assertEquals(1, rows.size());
Map stageRow = (Map) rows.get(0);
Map nodes = (Map) stageRow.get(NODES);
Assert.assertNotNull(nodes.get("first"));
Assert.assertNotNull(nodes.get("second"));
Assert.assertNotNull(nodes.get("third"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class JobAnalyticsTest method testJobAnalytics.
@Test
public void testJobAnalytics() throws Exception {
// Freestyle jobs
j.createFreeStyleProject("freestyle1").save();
j.createFreeStyleProject("freestyle2").save();
// Matrix job
j.createProject(MatrixProject.class, "bob");
// Create single scripted pipeline
WorkflowJob scriptedSingle = createWorkflowJobWithJenkinsfile(getClass(), "JobAnalyticsTest-scripted.jenkinsfile");
WorkflowRun scriptedSingleRun = scriptedSingle.scheduleBuild2(0, new CauseAction()).waitForStart();
j.waitForCompletion(scriptedSingleRun);
// Create single declarative pipeline
WorkflowJob declarativeSingle = createWorkflowJobWithJenkinsfile(getClass(), "JobAnalyticsTest-declarative.jenkinsfile");
WorkflowRun declarativeSingleRun = declarativeSingle.scheduleBuild2(0, new CauseAction()).waitForStart();
j.waitForCompletion(declarativeSingleRun);
// Create Scripted MultiBranch
createMultiBranch(sampleRepo);
// Create Declarative MultiBranch
createMultiBranch(sampleRepo2);
AnalyticsImpl analytics = (AnalyticsImpl) Analytics.get();
Assert.assertNotNull(analytics);
JobAnalytics jobAnalytics = new JobAnalytics();
jobAnalytics.calculateAndSend();
Assert.assertNotNull(analytics.lastReq);
Assert.assertEquals("job_stats", analytics.lastReq.name);
Map<String, Object> properties = analytics.lastReq.properties;
Assert.assertEquals("singlePipelineDeclarative", 1, properties.get("singlePipelineDeclarative"));
Assert.assertEquals("singlePipelineScripted", 1, properties.get("singlePipelineScripted"));
Assert.assertEquals("pipelineDeclarative", 1, properties.get("pipelineDeclarative"));
Assert.assertEquals("pipelineScripted", 1, properties.get("pipelineScripted"));
Assert.assertEquals("freestyle", 2, properties.get("freestyle"));
Assert.assertEquals("matrix", 1, properties.get("matrix"));
Assert.assertEquals("other", 0, properties.get("other"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelinePluginAnalyticsTest method createAndRunPipeline.
private void createAndRunPipeline(String jenkinsFileName) throws java.io.IOException, InterruptedException, java.util.concurrent.ExecutionException {
// Create the pipeline and run it
WorkflowJob scriptedSingle = createWorkflowJobWithJenkinsfile(getClass(), jenkinsFileName);
WorkflowRun scriptedSingleRun = scriptedSingle.scheduleBuild2(0, new CauseAction()).waitForStart();
j.waitForCompletion(scriptedSingleRun);
// RunListeners can sometimes be executed after the run is reported as completed. This fixes a race condition.
AnalyticsImpl analytics = (AnalyticsImpl) Analytics.get();
Assert.assertNotNull(analytics);
while (analytics.lastReq == null) {
Thread.sleep(100);
}
}
Aggregations