Search in sources :

Example 16 with SCMSource

use of jenkins.scm.api.SCMSource 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)

Example 17 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getMultiBranchPipelineRunStages.

@Test
public void getMultiBranchPipelineRunStages() 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());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(3, mp.getItems().size());
    j.waitForCompletion(b1);
    List<Map> nodes = get("/organizations/jenkins/pipelines/p/branches/master/runs/1/nodes", List.class);
    Assert.assertEquals(3, nodes.size());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 18 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getMultiBranchPipelineRuns.

@Test
public void getMultiBranchPipelineRuns() 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());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(3, mp.getItems().size());
    //execute feature/ux-1 branch build
    p = scheduleAndFindBranchProject(mp, "feature%2Fux-1");
    j.waitUntilNoActivity();
    WorkflowRun b2 = p.getLastBuild();
    assertEquals(1, b2.getNumber());
    //execute feature 2 branch build
    p = scheduleAndFindBranchProject(mp, "feature2");
    j.waitUntilNoActivity();
    WorkflowRun b3 = p.getLastBuild();
    assertEquals(1, b3.getNumber());
    List<Map> br = get("/organizations/jenkins/pipelines/p/branches", List.class);
    List<String> branchNames = new ArrayList<>();
    List<Integer> weather = new ArrayList<>();
    for (Map b : br) {
        branchNames.add((String) b.get("name"));
        weather.add((int) b.get("weatherScore"));
    }
    Assert.assertTrue(branchNames.contains(((Map) (br.get(0).get("latestRun"))).get("pipeline")));
    for (String n : branches) {
        assertTrue(branchNames.contains(n));
    }
    WorkflowRun[] runs = { b1, b2, b3 };
    int i = 0;
    for (String n : branches) {
        WorkflowRun b = runs[i];
        j.waitForCompletion(b);
        Map run = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(n) + "/runs/" + b.getId());
        validateRun(b, run);
        i++;
    }
    Map pr = get("/organizations/jenkins/pipelines/p/");
    validateMultiBranchPipeline(mp, pr, 3, 3, 0);
    sampleRepo.git("checkout", "master");
    sampleRepo.write("file", "subsequent content11");
    sampleRepo.git("commit", "--all", "--message=tweaked11");
    p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowRun b4 = p.getLastBuild();
    assertEquals(2, b4.getNumber());
    List<Map> run = get("/organizations/jenkins/pipelines/p/branches/master/runs/", List.class);
    validateRun(b4, run.get(0));
}
Also used : ArrayList(java.util.ArrayList) 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) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 19 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method declarativeSyntheticSkippedStage.

@Test
public void declarativeSyntheticSkippedStage() throws Exception {
    setupScm("pipeline {\n" + "    agent any\n" + "    stages {\n" + "        stage(\"build\") {\n" + "            steps{\n" + "              sh 'echo \"Start Build\"'\n" + "              echo 'End Build'\n" + "            }\n" + "        }\n" + "        stage(\"SkippedStage\") {\n" + "            when {\n" + "        expression {\n" + "                return false\n" + "        }\n" + "            }\n" + "            steps {\n" + "                script {\n" + "                    echo \"World\"\n" + "                    echo \"Heal it\"\n" + "                }\n" + "\n" + "            }\n" + "        }\n" + "        stage(\"deploy\") {\n" + "            steps{\n" + "              sh 'echo \"Start Deploy\"'\n" + "              sh 'echo \"Deploying...\"'\n" + "              sh 'echo \"End Deploy\"'\n" + "            }           \n" + "        }\n" + "    }\n" + "    post {\n" + "        failure {\n" + "            echo \"failed\"\n" + "        }\n" + "        success {\n" + "            echo \"success\"\n" + "        }\n" + "    }\n" + "}");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    mp.scheduleBuild2(0).getFuture().get();
    j.waitUntilNoActivity();
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    Assert.assertEquals(Result.SUCCESS, b1.getResult());
    List<FlowNode> stages = getStages(NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1));
    Assert.assertEquals(3, stages.size());
    Assert.assertEquals("build", stages.get(0).getDisplayName());
    Assert.assertEquals("SkippedStage", stages.get(1).getDisplayName());
    Assert.assertEquals("deploy", stages.get(2).getDisplayName());
    List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
    Assert.assertEquals(3, resp.size());
    Assert.assertEquals("build", resp.get(0).get("displayName"));
    Assert.assertEquals("SkippedStage", resp.get(1).get("displayName"));
    Assert.assertEquals("deploy", resp.get(2).get("displayName"));
    //check status
    Assert.assertEquals("SUCCESS", resp.get(0).get("result"));
    Assert.assertEquals("FINISHED", resp.get(0).get("state"));
    Assert.assertEquals("NOT_BUILT", resp.get(1).get("result"));
    Assert.assertEquals("SKIPPED", resp.get(1).get("state"));
    Assert.assertEquals("SUCCESS", resp.get(2).get("result"));
    Assert.assertEquals("FINISHED", resp.get(2).get("state"));
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/steps/", List.class);
    Assert.assertEquals(7, resp.size());
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(0).getId() + "/steps/", List.class);
    Assert.assertEquals(3, resp.size());
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(1).getId() + "/steps/", List.class);
    Assert.assertEquals(0, resp.size());
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(2).getId() + "/steps/", List.class);
    Assert.assertEquals(4, resp.size());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) RunList(hudson.util.RunList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 20 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getMultiBranchPipeline.

@Test
public void getMultiBranchPipeline() throws IOException, ExecutionException, InterruptedException {
    Assume.assumeTrue(runAllTests());
    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());
    }
    mp.scheduleBuild2(0).getFuture().get();
    Map resp = get("/organizations/jenkins/pipelines/p/");
    validateMultiBranchPipeline(mp, resp, 3);
    List<String> names = (List<String>) resp.get("branchNames");
    IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(names, branches);
    List<Map> br = get("/organizations/jenkins/pipelines/p/branches", List.class);
    List<String> branchNames = new ArrayList<>();
    List<Integer> weather = new ArrayList<>();
    for (Map b : br) {
        branchNames.add((String) b.get("name"));
        weather.add((int) b.get("weatherScore"));
    }
    for (String n : branches) {
        assertTrue(branchNames.contains(n));
    }
    for (int s : weather) {
        assertEquals(100, s);
    }
}
Also used : ArrayList(java.util.ArrayList) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

SCMSource (jenkins.scm.api.SCMSource)26 BranchSource (jenkins.branch.BranchSource)25 GitSCMSource (jenkins.plugins.git.GitSCMSource)25 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)25 Test (org.junit.Test)23 Map (java.util.Map)22 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)17 List (java.util.List)11 ImmutableList (com.google.common.collect.ImmutableList)10 ArrayList (java.util.ArrayList)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)7 MockFolder (org.jvnet.hudson.test.MockFolder)4 FreeStyleProject (hudson.model.FreeStyleProject)3 Queue (hudson.model.Queue)2 RunList (hudson.util.RunList)2 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)2 GitLabConnectionProperty (com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty)1 BuildData (hudson.plugins.git.util.BuildData)1