Search in sources :

Example 1 with BuildData

use of hudson.plugins.git.util.BuildData in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getMultiBranchPipelineActivityRuns.

@Test
public void getMultiBranchPipelineActivityRuns() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    scheduleAndFindBranchProject(mp);
    j.waitUntilNoActivity();
    WorkflowJob p = findBranchProject(mp, "master");
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(3, mp.getItems().size());
    // execute feature/ux-1 branch build
    p = findBranchProject(mp, "feature%2Fux-1");
    WorkflowRun b2 = p.getLastBuild();
    assertEquals(1, b2.getNumber());
    // execute feature 2 branch build
    p = findBranchProject(mp, "feature2");
    WorkflowRun b3 = p.getLastBuild();
    assertEquals(1, b3.getNumber());
    List<Map> resp = get("/organizations/jenkins/pipelines/p/runs", List.class);
    Assert.assertEquals(3, resp.size());
    Date d1 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String) resp.get(0).get("startTime"));
    Date d2 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String) resp.get(1).get("startTime"));
    Date d3 = new SimpleDateFormat(DATE_FORMAT_STRING).parse((String) resp.get(2).get("startTime"));
    Assert.assertTrue(d1.compareTo(d2) >= 0);
    Assert.assertTrue(d2.compareTo(d3) >= 0);
    for (Map m : resp) {
        BuildData d;
        WorkflowRun r;
        if (m.get("pipeline").equals("master")) {
            r = b1;
            d = b1.getAction(BuildData.class);
        } else if (m.get("pipeline").equals("feature2")) {
            r = b3;
            d = b3.getAction(BuildData.class);
        } else {
            r = b2;
            d = b2.getAction(BuildData.class);
        }
        validateRun(r, m);
        String commitId = "";
        if (d != null) {
            commitId = d.getLastBuiltRevision().getSha1String();
            Assert.assertEquals(commitId, m.get("commitId"));
        }
    }
}
Also used : 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) Date(java.util.Date) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) BuildData(hudson.plugins.git.util.BuildData) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 BuildData (hudson.plugins.git.util.BuildData)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1 BranchSource (jenkins.branch.BranchSource)1 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)1 GitSCMSource (jenkins.plugins.git.GitSCMSource)1 SCMSource (jenkins.scm.api.SCMSource)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)1 Test (org.junit.Test)1