Search in sources :

Example 66 with WorkflowJob

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

the class PipelineApiTest method getPipelineJobAbortTest.

@Test
public void getPipelineJobAbortTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   sh('sleep 60') " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    for (int i = 0; i < 10; i++) {
        b1.doStop();
        if (b1.getResult() != null) {
            break;
        }
        Thread.sleep(1000);
    }
    j.assertBuildStatus(Result.ABORTED, b1);
    Map r = get("/organizations/jenkins/pipelines/pipeline1/runs/1");
    validateRun(b1, r);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 67 with WorkflowJob

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

the class PipelineApiTest method getPipelineJobsTest.

@Test
public void getPipelineJobsTest() throws IOException {
    WorkflowJob p1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    WorkflowJob p2 = j.jenkins.createProject(WorkflowJob.class, "pipeline2");
    List<Map> resp = get("/organizations/jenkins/pipelines/", List.class);
    WorkflowJob[] projects = { p1, p2 };
    Assert.assertEquals(projects.length, resp.size());
    for (int i = 0; i < projects.length; i++) {
        Map lr = resp.get(i);
        validatePipeline(projects[i], lr);
    }
}
Also used : WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) Test(org.junit.Test)

Example 68 with WorkflowJob

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

the class PipelineNodeTest method KyotoNodesFailureTest2.

@Test
public void KyotoNodesFailureTest2() 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 \"Building\"'\n" + "            sh 'echo2 \"Building finished\"'\n" + "}\n" + "        }\n" + "        stage ('Deploy') {\n" + "steps{\n" + "            sh 'echo \"Building\"'\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("FAILURE", 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)

Aggregations

WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)68 Test (org.junit.Test)59 Map (java.util.Map)56 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)51 ImmutableMap (com.google.common.collect.ImmutableMap)46 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)46 List (java.util.List)26 ImmutableList (com.google.common.collect.ImmutableList)23 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)19 BranchSource (jenkins.branch.BranchSource)17 GitSCMSource (jenkins.plugins.git.GitSCMSource)17 SCMSource (jenkins.scm.api.SCMSource)17 RunList (hudson.util.RunList)16 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)14 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)13 ArrayList (java.util.ArrayList)8 FlowGraphTable (org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable)4 JSONObject (net.sf.json.JSONObject)3 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)3 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)3