Search in sources :

Example 1 with WorkflowRun

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

the class AbstractRunImplTest method replayRunTest.

//Disabled, see JENKINS-36453
//@Test
public void replayRunTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    j.createOnlineSlave(Label.get("remote"));
    job1.setDefinition(new CpsFlowDefinition("node('remote') {\n" + "    ws {\n" + "        git($/" + sampleRepo + "/$)\n" + "    }\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    sampleRepo.write("file1", "");
    sampleRepo.git("add", "file1");
    sampleRepo.git("commit", "--message=init");
    WorkflowRun b2 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b2);
    Assert.assertNotEquals(new PipelineRunImpl(b1, null).getCommitId(), new PipelineRunImpl(b2, null).getCommitId());
    request().post("/organizations/jenkins/pipelines/pipeline1/runs/1/replay").build(String.class);
    j.waitForCompletion(job1.getLastBuild());
    Map r = request().get("/organizations/jenkins/pipelines/pipeline1/runs/3/").build(Map.class);
    assertEquals(r.get("commitId"), new PipelineRunImpl(b2, null).getCommitId());
}
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)

Example 2 with WorkflowRun

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

the class MultiBranchTest method getMultiBranchPipelineRunChangeSets.

@Test
public void getMultiBranchPipelineRunChangeSets() throws Exception {
    setupScmWithChangeSet();
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo3.toString(), "", "*", "", false)));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(1, mp.getItems().size());
    String[] messages = { "tweaked11", "tweaked12", "tweaked13", "tweaked14" };
    sampleRepo3.git("checkout", "master");
    sampleRepo3.write("file", "subsequent content11");
    sampleRepo3.git("commit", "--all", "--message=" + messages[0]);
    sampleRepo3.git("checkout", "master");
    sampleRepo3.write("file", "subsequent content12");
    sampleRepo3.git("commit", "--all", "--message=" + messages[1]);
    sampleRepo3.git("checkout", "master");
    sampleRepo3.write("file", "subsequent content13");
    sampleRepo3.git("commit", "--all", "--message=" + messages[2]);
    sampleRepo3.git("checkout", "master");
    sampleRepo3.write("file", "subsequent content14");
    sampleRepo3.git("commit", "--all", "--message=" + messages[3]);
    WorkflowRun b4 = p.scheduleBuild2(0).get();
    j.waitUntilNoActivity();
    assertEquals(b4.getNumber(), 2);
    Assert.assertEquals(1, b4.getChangeSets().size());
    ChangeLogSet.Entry changeLog = b4.getChangeSets().get(0).iterator().next();
    int i = 0;
    for (ChangeLogSet.Entry c : b4.getChangeSets().get(0)) {
        Assert.assertEquals(messages[i], c.getMsg());
        i++;
    }
    Map run = get("/organizations/jenkins/pipelines/p/branches/master/runs/" + b4.getId() + "/");
    validateRun(b4, run);
    List<Map> changetSet = (List<Map>) run.get("changeSet");
    Map c = changetSet.get(0);
    Assert.assertEquals(changeLog.getCommitId(), c.get("commitId"));
    Map a = (Map) c.get("author");
    Assert.assertEquals(changeLog.getAuthor().getId(), a.get("id"));
    Assert.assertEquals(changeLog.getAuthor().getFullName(), a.get("fullName"));
    int j = 0;
    for (ChangeLogSet.Entry cs : b4.getChangeSets().get(0)) {
        Assert.assertEquals(cs.getCommitId(), changetSet.get(j).get("commitId"));
        j++;
    }
    Assert.assertEquals(i, j);
}
Also used : ChangeLogSet(hudson.scm.ChangeLogSet) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 3 with WorkflowRun

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

the class PipelineApiTest method getPipelineRunStopTest.

@Test
public void getPipelineRunStopTest() 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();
    Map r = null;
    for (int i = 0; i < 10; i++) {
        r = request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop").build(Map.class);
        if (((String) r.get("state")).equalsIgnoreCase("FINISHED"))
            continue;
        Thread.sleep(1000);
    }
    Assert.assertEquals(r.get("state"), "FINISHED");
    Assert.assertEquals(r.get("result"), "ABORTED");
    j.assertBuildStatus(Result.ABORTED, b1);
    FreeStyleProject p = j.createFreeStyleProject("pipeline5");
    p.getBuildersList().add(new Shell("echo hello!\nsleep 69"));
    FreeStyleBuild b2 = p.scheduleBuild2(0).waitForStart();
    for (int i = 0; i < 10; i++) {
        r = put("/organizations/jenkins/pipelines/pipeline5/runs/1/stop", null);
        if (((String) r.get("state")).equalsIgnoreCase("finished"))
            continue;
        Thread.sleep(1000);
    }
    Assert.assertEquals(r.get("state"), "FINISHED");
    Assert.assertEquals(r.get("result"), "ABORTED");
    j.assertBuildStatus(Result.ABORTED, b2);
}
Also used : Shell(hudson.tasks.Shell) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FreeStyleBuild(hudson.model.FreeStyleBuild) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 4 with WorkflowRun

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

the class PipelineApiTest method getPipelineFailingActionTest.

@Test
public void getPipelineFailingActionTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    WorkflowJob job2 = j.jenkins.createProject(WorkflowJob.class, "pipeline2");
    String script = "\n" + "node {\n" + "   stage ('Build'){ \n" + "     echo ('Building'); \n" + "   } \n" + "   stage ('Test') { \n" + "     echo ('Testing'); \n" + "   } \n" + "}";
    job1.setDefinition(new CpsFlowDefinition(script));
    job1.addAction(new ExplodingAction());
    job1.addAction(new TestAction());
    job2.setDefinition(new CpsFlowDefinition(script));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    b1.addAction(new ExplodingAction());
    b1.addAction(new TestAction());
    WorkflowRun b2 = job2.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b2);
    List<Map> pipelines = get("/organizations/jenkins/pipelines/", List.class);
    Assert.assertEquals(2, pipelines.size());
    validateBrokenAction((List<Map>) pipelines.get(0).get("actions"));
    Map pipeline = get("/organizations/jenkins/pipelines/pipeline1/");
    validatePipeline(job1, pipeline);
    validateBrokenAction((List<Map>) pipeline.get("actions"));
    List<Map> runs = get("/organizations/jenkins/pipelines/pipeline1/runs/", List.class);
    Assert.assertEquals(1, runs.size());
    validateBrokenAction((List<Map>) pipelines.get(0).get("actions"));
    Map resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1");
    validateBrokenAction((List<Map>) resp.get("actions"));
    validateRun(b1, resp);
}
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 5 with WorkflowRun

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

the class PipelineApiTest method getPipelineJobRunTest.

@Test
public void getPipelineJobRunTest() 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);
    Map resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1");
    validateRun(b1, resp);
}
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)

Aggregations

WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)53 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)50 Test (org.junit.Test)47 Map (java.util.Map)45 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)43 ImmutableMap (com.google.common.collect.ImmutableMap)37 List (java.util.List)17 ImmutableList (com.google.common.collect.ImmutableList)16 RunList (hudson.util.RunList)15 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)14 BranchSource (jenkins.branch.BranchSource)7 GitSCMSource (jenkins.plugins.git.GitSCMSource)7 SCMSource (jenkins.scm.api.SCMSource)7 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)7 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)4 JSONObject (net.sf.json.JSONObject)4 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)4 FlowGraphTable (org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable)4 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)3 Queue (hudson.model.Queue)2