Search in sources :

Example 6 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method parameterizedBranchTest.

@Test
public void parameterizedBranchTest() throws Exception {
    setupParameterizedScm();
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo2.toString(), "", "*", "", false)));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, branches[1]);
    j.waitUntilNoActivity();
    Map resp = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/", Map.class);
    List<Map<String, Object>> parameters = (List<Map<String, Object>>) resp.get("parameters");
    Assert.assertEquals(1, parameters.size());
    Assert.assertEquals("param1", parameters.get(0).get("name"));
    Assert.assertEquals("StringParameterDefinition", parameters.get(0).get("type"));
    Assert.assertEquals("string param", parameters.get(0).get("description"));
    Assert.assertEquals("xyz", ((Map) parameters.get(0).get("defaultParameterValue")).get("value"));
    resp = post("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/runs/", MapsHelper.of("parameters", Arrays.asList(MapsHelper.of("name", "param1", "value", "abc"))), 200);
    Assert.assertEquals(branches[1], resp.get("pipeline"));
    Thread.sleep(5000);
    resp = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/runs/2/");
    Assert.assertEquals("Response should be SUCCESS: " + resp.toString(), "SUCCESS", resp.get("result"));
    Assert.assertEquals("Response should be FINISHED: " + resp.toString(), "FINISHED", resp.get("state"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) 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) Test(org.junit.Test)

Example 7 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getBranchWithEncodedPath.

@Test
public void getBranchWithEncodedPath() throws IOException, ExecutionException, InterruptedException {
    Assume.assumeTrue(runAllTests());
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    FreeStyleProject f = j.jenkins.createProject(FreeStyleProject.class, "f");
    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();
    List<Map> resp = get("/organizations/jenkins/pipelines/p/branches/", List.class);
    String href = null;
    for (Map r : resp) {
        if (r.get("name").equals("feature%2Fux-1")) {
            href = (String) ((Map) ((Map) r.get("_links")).get("self")).get("href");
            href = StringUtils.substringAfter(href, "/blue/rest");
        }
    }
    Assert.assertNotNull(href);
    Map r = get(href);
    Assert.assertEquals("feature%2Fux-1", r.get("name"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) FreeStyleProject(hudson.model.FreeStyleProject) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) Test(org.junit.Test)

Example 8 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method multiBranchPipelineIndex.

@Test
public void multiBranchPipelineIndex() throws Exception {
    User user = login();
    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());
    }
    Map map = new RequestBuilder(baseUrl).post("/organizations/jenkins/pipelines/p/runs/").jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).crumb(getCrumb(j.jenkins)).data(Collections.emptyMap()).status(200).build(Map.class);
    assertNotNull(map);
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) User(hudson.model.User) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) Test(org.junit.Test)

Example 9 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getPipelinesTest.

@Test
public void getPipelinesTest() 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();
    List<Map> responses = get("/search/?q=type:pipeline;excludedFromFlattening:jenkins.branch.MultiBranchProject", List.class);
    Assert.assertEquals(1, responses.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) Test(org.junit.Test)

Example 10 with BranchSource

use of jenkins.branch.BranchSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testMbpPagination.

@Test
public void testMbpPagination() 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());
    }
    mp.scheduleBuild2(0).getFuture().get();
    this.j.waitUntilNoActivity();
    // create 6 runs
    List<WorkflowRun> launchedItems = new ArrayList<>();
    for (String branch : branches) {
        WorkflowJob job = findBranchProject(mp, branch);
        launchedItems.addAll(job.getBuilds());
        for (int j = 0; j < 2; j++) {
            launchedItems.add(job.scheduleBuild2(0).waitForStart());
            this.j.waitUntilNoActivity();
        }
    }
    // total 9. 3 triggered from indexing and 6 we launched
    assertEquals(9, launchedItems.size());
    // sort runs
    Collections.sort(launchedItems, new Comparator<WorkflowRun>() {

        @Override
        public int compare(WorkflowRun o1, WorkflowRun o2) {
            return new Date(o2.getStartTimeInMillis()).compareTo(new Date(o1.getStartTimeInMillis()));
        }
    });
    // request 10 runs, but should not return 9 runs.
    List<Map> resp = get("/organizations/jenkins/pipelines/p/runs?start=0&limit=10", List.class);
    // max number of runs are 9
    assertEquals(9, resp.size());
    for (int i = 0; i < 9; i++) {
        Assert.assertEquals(launchedItems.get(i).getId(), (resp.get(i).get("id")));
    }
    // now call 3 out of 9 runs and see pagination returns only 3 and in right sort order
    resp = get("/organizations/jenkins/pipelines/p/runs?start=0&limit=3", List.class);
    assertEquals(3, resp.size());
    for (int i = 0; i < 3; i++) {
        Assert.assertEquals(launchedItems.get(i).getId(), (resp.get(i).get("id")));
    }
}
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) Date(java.util.Date) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) Test(org.junit.Test)

Aggregations

BranchSource (jenkins.branch.BranchSource)42 GitSCMSource (jenkins.plugins.git.GitSCMSource)39 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)39 SCMSource (jenkins.scm.api.SCMSource)35 Test (org.junit.Test)34 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)32 Map (java.util.Map)26 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)25 List (java.util.List)16 ArrayList (java.util.ArrayList)15 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)13 User (hudson.model.User)6 Queue (hudson.model.Queue)5 MockFolder (org.jvnet.hudson.test.MockFolder)5 ExtensionList (hudson.ExtensionList)3 FreeStyleProject (hudson.model.FreeStyleProject)3 RunList (hudson.util.RunList)3 ImmutableList (com.google.common.collect.ImmutableList)2 Cause (hudson.model.Cause)2 OneShotEvent (hudson.util.OneShotEvent)2