newProjectFactory() {
49 | return new PipelineBranchDefaultsProjectFactory();
50 | }
51 |
52 | @Extension
53 | public static class DescriptorImpl extends WorkflowMultiBranchProject.DescriptorImpl {
54 |
55 | @Nonnull
56 | @Override
57 | public String getDisplayName() {
58 | return DefaultsMessages.PipelineMultiBranchDefaultsProject_DisplayName();
59 | }
60 |
61 | public String getDescription() {
62 | return DefaultsMessages.PipelineMultiBranchDefaultsProject_Description();
63 | }
64 |
65 | public String getIconFilePathPattern() {
66 | return "plugin/pipeline-multibranch-defaults/images/:size/pipelinemultibranchdefaultsproject.png";
67 | }
68 |
69 | @Override
70 | public TopLevelItem newInstance(ItemGroup parent, String name) {
71 | return new PipelineMultiBranchDefaultsProject(parent, name);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/pipeline/multibranch/defaults/DefaultsMessages.properties:
--------------------------------------------------------------------------------
1 | PipelineMultiBranchDefaultsProject.DisplayName=Multibranch Pipeline with defaults
2 | PipelineMultiBranchDefaultsProject.Description=Extend Multibranch pipeline plugin and build branches it the default prepred pipeline script.\
3 | Creates a set of Pipeline projects according to detected branches in one SCM repository.
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/pipeline/multibranch/defaults/PipelineBranchDefaultsProjectFactory/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/pipeline/multibranch/defaults/PipelineBranchDefaultsProjectFactory/getting-started.jelly:
--------------------------------------------------------------------------------
1 |
24 |
25 |
26 | Pipeline Branch projects support building branches within a repository with a file named
27 | Jenkinsfile
28 | in the Jenkins global files or scm module root directory.
29 | This file should contain a valid
30 | Jenkins
32 | Pipeline script. See also:
33 |
35 | Workflow Multibranch Plugin.
36 |
38 | Creating Multibranch Projects.
39 |
40 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/pipeline/multibranch/defaults/index.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 | Extension for workflow-multibranch-plugin. Automatically build branches the prepared default pipeline script.
29 |
30 |
--------------------------------------------------------------------------------
/src/main/webapp/images/48x48/pipelinemultibranchdefaultsproject.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vaimr/pipeline-multibranch-defaults-plugin/37c50abd281fb885914c9b0567a47527d82486c8/src/main/webapp/images/48x48/pipelinemultibranchdefaultsproject.png
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/pipeline/multibranch/defaults/DefaultsBinderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2016 Saponenko Denis
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.pipeline.multibranch.defaults;
26 |
27 | import jenkins.branch.BranchProperty;
28 | import jenkins.branch.BranchSource;
29 | import jenkins.branch.DefaultBranchPropertyStrategy;
30 | import jenkins.plugins.git.GitSCMSource;
31 | import jenkins.plugins.git.GitSampleRepoRule;
32 | import org.jenkinsci.lib.configprovider.ConfigProvider;
33 | import org.jenkinsci.lib.configprovider.model.Config;
34 | import org.jenkinsci.plugins.configfiles.ConfigFileStore;
35 | import org.jenkinsci.plugins.configfiles.GlobalConfigFiles;
36 | import org.jenkinsci.plugins.configfiles.groovy.GroovyScript;
37 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
38 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
39 | import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
40 | import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
41 | import org.junit.ClassRule;
42 | import org.junit.Rule;
43 | import org.junit.Test;
44 | import org.jvnet.hudson.test.BuildWatcher;
45 | import org.jvnet.hudson.test.JenkinsRule;
46 |
47 | import static net.sf.ezmorph.test.ArrayAssertions.assertEquals;
48 | import static org.junit.Assert.assertNotNull;
49 |
50 | public class DefaultsBinderTest {
51 | @ClassRule
52 | public static BuildWatcher buildWatcher = new BuildWatcher();
53 | @Rule
54 | public JenkinsRule r = new JenkinsRule();
55 | @Rule
56 | public GitSampleRepoRule sampleGitRepo = new GitSampleRepoRule();
57 |
58 |
59 | @Test
60 | public void testDefaultJenkinsFile() throws Exception {
61 | GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
62 | ConfigFileStore store = globalConfigFiles.get();
63 |
64 | Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
65 | "semaphore 'wait'; node {checkout scm; echo readFile('file')}");
66 | store.save(config);
67 |
68 | sampleGitRepo.init();
69 | sampleGitRepo.write("file", "initial content");
70 | sampleGitRepo.git("commit", "--all", "--message=flow");
71 | WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
72 | mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
73 | new DefaultBranchPropertyStrategy(new BranchProperty[0])));
74 | WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
75 | SemaphoreStep.waitForStart("wait/1", null);
76 | WorkflowRun b1 = p.getLastBuild();
77 | assertNotNull(b1);
78 | assertEquals(1, b1.getNumber());
79 | SemaphoreStep.success("wait/1", null);
80 | r.assertLogContains("initial content", r.waitForCompletion(b1));
81 | }
82 |
83 | @Test
84 | public void testDefaultJenkinsFileLoadFromWorkspace() throws Exception {
85 | GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
86 | ConfigFileStore store = globalConfigFiles.get();
87 | Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
88 | "semaphore 'wait'; node {checkout scm; load 'Jenkinsfile'}");
89 | store.save(config);
90 |
91 |
92 | sampleGitRepo.init();
93 | sampleGitRepo.write("Jenkinsfile", "echo readFile('file')");
94 | sampleGitRepo.git("add", "Jenkinsfile");
95 | sampleGitRepo.write("file", "initial content");
96 | sampleGitRepo.git("commit", "--all", "--message=flow");
97 | WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
98 | mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
99 | new DefaultBranchPropertyStrategy(new BranchProperty[0])));
100 | WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
101 | SemaphoreStep.waitForStart("wait/1", null);
102 | WorkflowRun b1 = p.getLastBuild();
103 | assertNotNull(b1);
104 | assertEquals(1, b1.getNumber());
105 | SemaphoreStep.success("wait/1", null);
106 | r.assertLogContains("initial content", r.waitForCompletion(b1));
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/pipeline/multibranch/defaults/PipelineBranchDefaultsProjectFactoryTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2016 Saponenko Denis
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.pipeline.multibranch.defaults;
26 |
27 | import jenkins.branch.BranchSource;
28 | import jenkins.plugins.git.GitSCMSource;
29 | import jenkins.plugins.git.GitSampleRepoRule;
30 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
31 | import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
32 | import org.junit.ClassRule;
33 | import org.junit.Rule;
34 | import org.junit.Test;
35 | import org.jvnet.hudson.test.BuildWatcher;
36 | import org.jvnet.hudson.test.JenkinsRule;
37 |
38 | import static net.sf.ezmorph.test.ArrayAssertions.assertEquals;
39 |
40 | public class PipelineBranchDefaultsProjectFactoryTest {
41 | @ClassRule
42 | public static BuildWatcher buildWatcher = new BuildWatcher();
43 | @Rule
44 | public JenkinsRule r = new JenkinsRule();
45 | @Rule
46 | public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();
47 |
48 | @Test
49 | public void allBranches() throws Exception {
50 | sampleRepo.init();
51 | sampleRepo.git("checkout", "-b", "dev/main");
52 | sampleRepo.write("file", "initial content");
53 | sampleRepo.git("add", "file");
54 | sampleRepo.git("commit", "--all", "--message=flow");
55 | WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
56 | mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)));
57 | WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "dev%2Fmain");
58 | assertEquals(2, mp.getItems().size());
59 | }
60 |
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/pipeline/multibranch/defaults/PipelineMultiBranchDefaultsProjectTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright (c) 2016 Saponenko Denis
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.pipeline.multibranch.defaults;
26 |
27 | import com.cloudbees.hudson.plugins.folder.computed.FolderComputation;
28 | import org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineBranchDefaultsProjectFactory;
29 | import org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineMultiBranchDefaultsProject;
30 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
31 | import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject;
32 | import org.junit.Rule;
33 | import org.junit.Test;
34 | import org.jvnet.hudson.test.JenkinsRule;
35 |
36 | import javax.annotation.Nonnull;
37 |
38 | import static junit.framework.TestCase.fail;
39 | import static org.junit.Assert.assertTrue;
40 |
41 | /**
42 | * Created by dsaponenko on 09.10.16.
43 | */
44 | public class PipelineMultiBranchDefaultsProjectTest {
45 | @Rule
46 | public JenkinsRule r = new JenkinsRule();
47 |
48 | @Test
49 | public void newProjectFactory() throws Exception {
50 | assertTrue(r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "test").
51 | newProjectFactory() instanceof PipelineBranchDefaultsProjectFactory);
52 | }
53 |
54 |
55 | public static
56 | @Nonnull
57 | WorkflowJob scheduleAndFindBranchProject(@Nonnull WorkflowMultiBranchProject mp, @Nonnull String name) throws Exception {
58 | mp.scheduleBuild2(0).getFuture().get();
59 | return findBranchProject(mp, name);
60 | }
61 |
62 | public static
63 | @Nonnull
64 | WorkflowJob findBranchProject(@Nonnull WorkflowMultiBranchProject mp, @Nonnull String name) throws Exception {
65 | WorkflowJob p = mp.getItem(name);
66 | showIndexing(mp);
67 | if (p == null) {
68 | fail(name + " project not found");
69 | }
70 | return p;
71 | }
72 |
73 | static void showIndexing(@Nonnull WorkflowMultiBranchProject mp) throws Exception {
74 | FolderComputation> indexing = mp.getIndexing();
75 | System.out.println("---%<--- " + indexing.getUrl());
76 | indexing.writeWholeLogTo(System.out);
77 | System.out.println("---%<--- ");
78 | }
79 | }
--------------------------------------------------------------------------------