Java Code Examples for jenkins.branch.BranchSource#setBuildStrategies()

The following examples show how to use jenkins.branch.BranchSource#setBuildStrategies() . 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: 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 2
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 3
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 4
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void tag____() 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("", "")));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new TagBuildStrategyImpl("", "")));
    }
}
 
Example 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
Source File: GitLabSCMItemListener.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 6 votes vote down vote up
private boolean updateBranchBuildStrategies(MultiBranchProject<?, ?> project) {
    boolean changed = false;

    for (BranchSource branchSource : project.getSources()) {
        if (GitLabSCMBranchBuildStrategy.INSTANCE.isApplicable(branchSource)) {
            List<BranchBuildStrategy> strategies = new ArrayList<>(branchSource.getBuildStrategies());
            if (!strategies.contains(GitLabSCMBranchBuildStrategy.INSTANCE)) {
                strategies.add(GitLabSCMBranchBuildStrategy.INSTANCE);
                branchSource.setBuildStrategies(strategies);
                changed = true;
            }
        }
    }

    return changed;
}
 
Example 13
Source File: FormBindingTest.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
@Test
public void branch() 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 BranchBuildStrategyImpl()));
        prj.getSourcesList().add(source);
        j.configRoundtrip(prj);
        assertThat(prj.getSources().get(0).getBuildStrategies(),
                contains((BranchBuildStrategy) new BranchBuildStrategyImpl()));
    }
}