jenkins.branch.BranchSource Java Examples

The following examples show how to use jenkins.branch.BranchSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitLabSCMSourceDeserializationTest.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
@Test
public void afterRestartingJenkinsTransientFieldsAreNotNull() throws Exception {
    plan.then(j -> {
        GitLabSCMSourceBuilder sb = new GitLabSCMSourceBuilder(SOURCE_ID, "server", "creds", "po", "group/project", "project");
        WorkflowMultiBranchProject project = j.createProject(WorkflowMultiBranchProject.class, PROJECT_NAME);
        project.getSourcesList().add(new BranchSource(sb.build()));
    });

    plan.then(j -> {
        SCMSource source = j.getInstance()
                .getAllItems(WorkflowMultiBranchProject.class)
                .stream().filter(p -> PROJECT_NAME.equals(p.getName()))
                .map(p -> p.getSCMSource(SOURCE_ID))
                .findFirst()
                .get();

        Class<? extends SCMSource> clazz = source.getClass();
        Field mergeRequestContributorCache = clazz.getDeclaredField("mergeRequestContributorCache");
        mergeRequestContributorCache.setAccessible(true);
        Field mergeRequestMetadataCache = clazz.getDeclaredField("mergeRequestMetadataCache");
        mergeRequestMetadataCache.setAccessible(true);
        assertNotNull(mergeRequestMetadataCache.get(source));
        assertNotNull(mergeRequestContributorCache.get(source));
    });
}
 
Example #2
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void changeRequest2() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "foo");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(),
                new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests()));
        source.setBuildStrategies(
                Collections.<BranchBuildStrategy>singletonList(new ChangeRequestBuildStrategyImpl(true, false)));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new ChangeRequestBuildStrategyImpl(true, false)));
    }
}
 
Example #3
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void changeRequest1() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "foo");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(),
                new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests()));
        source.setBuildStrategies(
                Collections.<BranchBuildStrategy>singletonList(new ChangeRequestBuildStrategyImpl(false, false)));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new ChangeRequestBuildStrategyImpl(false, false)));
    }
}
 
Example #4
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void namedBranch() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "foo");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(),
                new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests()));
        source.setBuildStrategies(Collections.<BranchBuildStrategy>singletonList(new NamedBranchBuildStrategyImpl(
                Arrays.asList(new NamedBranchBuildStrategyImpl.ExactNameFilter("master", false),
                        new NamedBranchBuildStrategyImpl.ExactNameFilter("production", false),
                        new NamedBranchBuildStrategyImpl.RegexNameFilter("^staging-.*$", false),
                        new NamedBranchBuildStrategyImpl.WildcardsNameFilter("feature/*", "feature", false)
                ))));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new NamedBranchBuildStrategyImpl(
                        Arrays.asList(new NamedBranchBuildStrategyImpl.ExactNameFilter("master", false),
                                new NamedBranchBuildStrategyImpl.ExactNameFilter("production", false),
                                new NamedBranchBuildStrategyImpl.RegexNameFilter("^staging-.*$", false),
                                new NamedBranchBuildStrategyImpl.WildcardsNameFilter("feature/*", "feature", false)
                        ))));
    }
}
 
Example #5
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void tagp1__() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "foo");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(),
                new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests()));
        source.setBuildStrategies(
                Collections.<BranchBuildStrategy>singletonList(new TagBuildStrategyImpl("1", "")));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new TagBuildStrategyImpl("1", "")));
    }
}
 
Example #6
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void tag__n1() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "foo");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(),
                new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests()));
        source.setBuildStrategies(
                Collections.<BranchBuildStrategy>singletonList(new TagBuildStrategyImpl("", "-1")));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new TagBuildStrategyImpl("", "")));
    }
}
 
Example #7
Source File: SkipInitialBuildOnFirstBranchIndexingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void if__first__branch__indexing__isAutomaticBuild__then__returns__true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "project");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches()));
        source.setBuildStrategies(Collections.<BranchBuildStrategy>singletonList(new SkipInitialBuildOnFirstBranchIndexing()));
        prj.getSourcesList().add(source);
        fire(new MockSCMHeadEvent(SCMEvent.Type.CREATED, c, "foo", "master", c.getRevision("foo", "master")));
        FreeStyleProject master = prj.getItem("master");
        j.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), nullValue());
        c.addFile("foo", "master", "adding file", "file", new byte[0]);
        fire(new MockSCMHeadEvent(SCMEvent.Type.UPDATED, c, "foo", "master", c.getRevision("foo", "master")));
        j.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assertThat("The master branch was built", master.getLastBuild().getNumber(), is(1));
        c.addFile("foo", "master", "adding file", "file", new byte[0]);
        fire(new MockSCMHeadEvent(SCMEvent.Type.UPDATED, c, "foo", "master", c.getRevision("foo", "master")));
        j.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assertThat("The master branch was built", master.getLastBuild().getNumber(), is(2));
    }
}
 
Example #8
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void tagn1__() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "foo");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(),
                new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests()));
        source.setBuildStrategies(
                Collections.<BranchBuildStrategy>singletonList(new TagBuildStrategyImpl("-1", "")));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new TagBuildStrategyImpl("", "")));
    }
}
 
Example #9
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void tag___0() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "foo");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(),
                new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests()));
        source.setBuildStrategies(
                Collections.<BranchBuildStrategy>singletonList(new TagBuildStrategyImpl("", "0")));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new TagBuildStrategyImpl("", "0")));
    }
}
 
Example #10
Source File: SkipInitialBuildOnFirstBranchIndexingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void if__skipInitialBuildOnFirstBranchIndexing__is__disabled__first__branch__indexing__triggers__the__build() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "my-project");
        prj.setCriteria(null);
        prj.getSourcesList().add(new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches())));
        fire(new MockSCMHeadEvent(SCMEvent.Type.CREATED, c, "foo", "master", c.getRevision("foo", "master")));
        FreeStyleProject master = prj.getItem("master");
        j.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild().getNumber(), is(1));
        c.addFile("foo", "master", "adding file", "file", new byte[0]);
        fire(new MockSCMHeadEvent(SCMEvent.Type.UPDATED, c, "foo", "master", c.getRevision("foo", "master")));
        j.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assertThat("The master branch was built", master.getLastBuild().getNumber(), is(2));
    }
}
 
Example #11
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void tag__p1() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "foo");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(),
                new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests()));
        source.setBuildStrategies(
                Collections.<BranchBuildStrategy>singletonList(new TagBuildStrategyImpl("", "1")));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new TagBuildStrategyImpl("", "1")));
    }
}
 
Example #12
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void tag_0__() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        BasicMultiBranchProject prj = j.jenkins.createProject(BasicMultiBranchProject.class, "foo");
        prj.setCriteria(null);
        BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches(),
                new MockSCMDiscoverTags(), new MockSCMDiscoverChangeRequests()));
        source.setBuildStrategies(
                Collections.<BranchBuildStrategy>singletonList(new TagBuildStrategyImpl("0", "")));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new TagBuildStrategyImpl("0", "")));
    }
}
 
Example #13
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void resolveMbpLink() throws Exception {
    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();

    j.waitUntilNoActivity();

    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/",LinkResolver.resolveLink(mp).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/",LinkResolver.resolveLink(mp.getBranch("master")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature%252Fux-1/",LinkResolver.resolveLink(mp.getBranch("feature%2Fux-1")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/",LinkResolver.resolveLink(mp.getBranch("feature2")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/f/",LinkResolver.resolveLink(f).getHref());
}
 
Example #14
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getMultiBranchPipelines() 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/", List.class);
    Assert.assertEquals(2, resp.size());
    validatePipeline(f, resp.get(0));
    validateMultiBranchPipeline(mp, resp.get(1), 3);
    Assert.assertEquals(mp.getBranch("master").getBuildHealth().getScore(), resp.get(0).get("weatherScore"));
}
 
Example #15
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getMultiBranchPipelineInsideFolder() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");
    mp.setDisplayName("My MBP");

    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 r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");

    validateMultiBranchPipeline(mp, r, 3);
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/p/",
        ((Map)((Map)r.get("_links")).get("self")).get("href"));
    Assert.assertEquals("folder1/My%20MBP", r.get("fullDisplayName"));
    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/master/");
    Assert.assertEquals("folder1/My%20MBP/master", r.get("fullDisplayName"));
}
 
Example #16
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getMultiBranchPipelinesWithNonMasterBranch() throws Exception {
    sampleRepo.git("checkout", "feature2");
    sampleRepo.git("branch","-D", "master");
    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();

    List<Map> resp = get("/organizations/jenkins/pipelines/", List.class);
    Assert.assertEquals(1, resp.size());
    validateMultiBranchPipeline(mp, resp.get(0), 2);
    assertNull(mp.getBranch("master"));
}
 
Example #17
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@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(ImmutableMap.of())
            .status(200)
            .build(Map.class);

    assertNotNull(map);
}
 
Example #18
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void startMultiBranchPipelineRuns() 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, "feature%2Fux-1");
    j.waitUntilNoActivity();

    Map resp = post("/organizations/jenkins/pipelines/p/branches/"+ Util.rawEncode("feature%2Fux-1")+"/runs/",
        Collections.EMPTY_MAP);
    String id = (String) resp.get("id");
    String link = getHrefFromLinks(resp, "self");
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature%252Fux-1/runs/"+id+"/", link);
}
 
Example #19
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@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());
}
 
Example #20
Source File: MultiBranchTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@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());
}
 
Example #21
Source File: DefaultsBinderTest.java    From pipeline-multibranch-defaults-plugin with MIT License 6 votes vote down vote up
@Test
public void testDefaultJenkinsFile() throws Exception {
    GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
    ConfigFileStore store = globalConfigFiles.get();

    Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
        "semaphore 'wait'; node {checkout scm; echo readFile('file')}");
    store.save(config);

    sampleGitRepo.init();
    sampleGitRepo.write("file", "initial content");
    sampleGitRepo.git("commit", "--all", "--message=flow");
    WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
    SemaphoreStep.waitForStart("wait/1", null);
    WorkflowRun b1 = p.getLastBuild();
    assertNotNull(b1);
    assertEquals(1, b1.getNumber());
    SemaphoreStep.success("wait/1", null);
    r.assertLogContains("initial content", r.waitForCompletion(b1));
}
 
Example #22
Source File: DefaultsBinderTest.java    From pipeline-multibranch-defaults-plugin with MIT License 6 votes vote down vote up
@Test
public void testDefaultJenkinsFileLoadFromWorkspace() throws Exception {
    GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
    ConfigFileStore store = globalConfigFiles.get();
    Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
        "semaphore 'wait'; node {checkout scm; load 'Jenkinsfile'}");
    store.save(config);


    sampleGitRepo.init();
    sampleGitRepo.write("Jenkinsfile", "echo readFile('file')");
    sampleGitRepo.git("add", "Jenkinsfile");
    sampleGitRepo.write("file", "initial content");
    sampleGitRepo.git("commit", "--all", "--message=flow");
    WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
    SemaphoreStep.waitForStart("wait/1", null);
    WorkflowRun b1 = p.getLastBuild();
    assertNotNull(b1);
    assertEquals(1, b1.getNumber());
    SemaphoreStep.success("wait/1", null);
    r.assertLogContains("initial content", r.waitForCompletion(b1));
}
 
Example #23
Source File: GitHubSCMSourceTest.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Test
@Issue("JENKINS-48035")
public void testGitHubRepositoryNameContributor() throws IOException {
    WorkflowMultiBranchProject job = r.createProject(WorkflowMultiBranchProject.class);
    job.setSourcesList(Arrays.asList(new BranchSource(source)));
    Collection<GitHubRepositoryName> names = GitHubRepositoryNameContributor.parseAssociatedNames(job);
    assertThat(names, contains(allOf(
            hasProperty("userName", equalTo("cloudbeers")),
            hasProperty("repositoryName", equalTo("yolo"))
    )));
    //And specifically...
    names = new ArrayList<>();
    ExtensionList.lookup(GitHubRepositoryNameContributor.class).get(GitHubSCMSourceRepositoryNameContributor.class).parseAssociatedNames(job, names);
    assertThat(names, contains(allOf(
            hasProperty("userName", equalTo("cloudbeers")),
            hasProperty("repositoryName", equalTo("yolo"))
    )));
}
 
Example #24
Source File: FreeStyleMultiBranchProjectTest.java    From multi-branch-project-plugin with MIT License 6 votes vote down vote up
@Test
public void given_multibranchWithSources_when_indexing_then_branchesAreFoundAndBuilt() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        FreeStyleMultiBranchProject prj = r.jenkins.createProject(FreeStyleMultiBranchProject.class, "foo");
        prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
        prj.scheduleBuild2(0).getFuture().get();
        r.waitUntilNoActivity();
        assertThat("We now have branches",
                prj.getItems(), not(is((Collection<FreeStyleProject>) Collections.<FreeStyleProject>emptyList())));
        FreeStyleProject master = prj.getItem("master");
        assertThat("We now have the master branch", master, notNullValue());
        r.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assertThat("The master branch was built", master.getLastBuild().getNumber(), is(1));
    }
}
 
Example #25
Source File: FreeStyleMultiBranchProjectTest.java    From multi-branch-project-plugin with MIT License 6 votes vote down vote up
@Test
public void given_multibranchWithSources_when_indexingWithFancyNames_then_branchesAreFoundAndBuilt() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        c.cloneBranch("foo", "master", "feature/jenkins-41867");
        FreeStyleMultiBranchProject prj = r.jenkins.createProject(FreeStyleMultiBranchProject.class, "foo");
        prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
        prj.scheduleBuild2(0).getFuture().get();
        r.waitUntilNoActivity();
        System.out.println(FileUtils.readFileToString(prj.getIndexing().getLogFile()));
        assertThat(prj.getIndexing().getResult(), is(Result.SUCCESS));
        assertThat("We now have branches",
                prj.getItems(), not(is((Collection<FreeStyleProject>) Collections.<FreeStyleProject>emptyList())));
        FreeStyleProject master = prj.getItem("master");
        assertThat("We now have the master branch", master, notNullValue());
        r.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assertThat("The master branch was built", master.getLastBuild().getNumber(), is(1));
    }
}
 
Example #26
Source File: FreeStyleMultiBranchProjectTest.java    From multi-branch-project-plugin with MIT License 6 votes vote down vote up
@Test
public void given_multibranchWithSources_when_matchingEvent_then_branchesAreFoundAndBuilt() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        FreeStyleMultiBranchProject prj = r.jenkins.createProject(FreeStyleMultiBranchProject.class, "foo");
        prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
        fire(new MockSCMHeadEvent("given_multibranchWithSources_when_matchingEvent_then_branchesAreFoundAndBuilt", SCMEvent.Type.UPDATED, c, "foo", "master", "junkHash"));
        assertThat("We now have branches",
                prj.getItems(), not(is((Collection<FreeStyleProject>) Collections.<FreeStyleProject>emptyList())));
        FreeStyleProject master = prj.getItem("master");
        assertThat("We now have the master branch", master, notNullValue());
        r.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assertThat("The master branch was built", master.getLastBuild().getNumber(), is(1));
    }
}
 
Example #27
Source File: FreeStyleMultiBranchProjectTest.java    From multi-branch-project-plugin with MIT License 6 votes vote down vote up
@Test
@Ignore("Currently failing to honour contract of multi-branch projects with respect to dead branches")
public void given_multibranchWithSources_when_accessingBranch_then_branchCannotBeDeleted() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        FreeStyleMultiBranchProject prj = r.jenkins.createProject(FreeStyleMultiBranchProject.class, "foo");
        prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
        prj.scheduleBuild2(0).getFuture().get();
        r.waitUntilNoActivity();
        assertThat("We now have branches",
                prj.getItems(), not(is((Collection<FreeStyleProject>) Collections.<FreeStyleProject>emptyList())));
        FreeStyleProject master = prj.getItem("master");
        assertThat("We now have the master branch", master, notNullValue());
        r.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assertThat(master.getACL().hasPermission(ACL.SYSTEM, Item.DELETE), is(false));
    }
}
 
Example #28
Source File: FreeStyleMultiBranchProjectTest.java    From multi-branch-project-plugin with MIT License 6 votes vote down vote up
@Test
public void given_multibranchWithSources_when_accessingDeadBranch_then_branchCanBeDeleted() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        FreeStyleMultiBranchProject prj = r.jenkins.createProject(FreeStyleMultiBranchProject.class, "foo");
        prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
        prj.scheduleBuild2(0).getFuture().get();
        r.waitUntilNoActivity();
        assertThat("We now have branches",
                prj.getItems(), not(is((Collection<FreeStyleProject>) Collections.<FreeStyleProject>emptyList())));
        FreeStyleProject master = prj.getItem("master");
        assertThat("We now have the master branch", master, notNullValue());
        r.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assumeThat(master.getACL().hasPermission(ACL.SYSTEM, Item.DELETE), is(false));
        c.deleteBranch("foo", "master");
        fire(new MockSCMHeadEvent(
                "given_multibranchWithSources_when_branchRemoved_then_branchProjectIsNotBuildable",
                SCMEvent.Type.REMOVED, c, "foo", "master", "junkHash"));
        r.waitUntilNoActivity();
        assertThat(master.getACL().hasPermission(ACL.SYSTEM, Item.DELETE), is(true));
    }
}
 
Example #29
Source File: FreeStyleMultiBranchProjectTest.java    From multi-branch-project-plugin with MIT License 6 votes vote down vote up
@Test
public void given_multibranchWithSources_when_accessingBranch_then_branchCanBeBuilt() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        FreeStyleMultiBranchProject prj = r.jenkins.createProject(FreeStyleMultiBranchProject.class, "foo");
        prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
        prj.scheduleBuild2(0).getFuture().get();
        r.waitUntilNoActivity();
        assertThat("We now have branches",
                prj.getItems(), not(is((Collection<FreeStyleProject>) Collections.<FreeStyleProject>emptyList())));
        FreeStyleProject master = prj.getItem("master");
        assertThat("We now have the master branch", master, notNullValue());
        r.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assertThat(master.isBuildable(), is(true));
    }
}
 
Example #30
Source File: FreeStyleMultiBranchProjectTest.java    From multi-branch-project-plugin with MIT License 6 votes vote down vote up
@Test
@Ignore("Currently failing to honour contract of multi-branch projects with respect to dead branches")
public void given_multibranchWithSources_when_accessingDeadBranch_then_branchCannotBeBuilt() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("foo");
        FreeStyleMultiBranchProject prj = r.jenkins.createProject(FreeStyleMultiBranchProject.class, "foo");
        prj.getSourcesList().add(new BranchSource(new MockSCMSource(null, c, "foo", true, false, false)));
        prj.scheduleBuild2(0).getFuture().get();
        r.waitUntilNoActivity();
        assertThat("We now have branches",
                prj.getItems(), not(is((Collection<FreeStyleProject>) Collections.<FreeStyleProject>emptyList())));
        FreeStyleProject master = prj.getItem("master");
        assertThat("We now have the master branch", master, notNullValue());
        r.waitUntilNoActivity();
        assertThat("The master branch was built", master.getLastBuild(), notNullValue());
        assumeThat(master.isBuildable(), is(true));
        c.deleteBranch("foo", "master");
        fire(new MockSCMHeadEvent(
                "given_multibranchWithSources_when_branchRemoved_then_branchProjectIsNotBuildable",
                SCMEvent.Type.REMOVED, c, "foo", "master", "junkHash"));
        r.waitUntilNoActivity();
        assertThat(master.isBuildable(), is(false));
    }
}