diff --git a/images/config-driven-pipeline-project-recognizer.png b/images/config-driven-pipeline-project-recognizer.png index 8ec025a..27e1574 100644 Binary files a/images/config-driven-pipeline-project-recognizer.png and b/images/config-driven-pipeline-project-recognizer.png differ diff --git a/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory.java b/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory.java index d2c546d..d78c3a8 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory.java @@ -21,15 +21,20 @@ public class ConfigDrivenWorkflowBranchProjectFactory extends AbstractWorkflowBranchProjectFactory { // TODO: Make this a parameter that users can adjust to their liking public static final String USER_DEFINITION_PATH = ".yourconfig.yml"; + public static final String USER_DEFINITION_PIPELINE_PATH = "Jenkinsfile"; public static final String PIPELINE_TEMPLATE = "pipeline_template"; private String scriptPath = USER_DEFINITION_PATH; + private String pipelinePath = USER_DEFINITION_PIPELINE_PATH; private SCM jenkinsFileScm = null; public Object readResolve() { if (this.scriptPath == null) { this.scriptPath = USER_DEFINITION_PATH; } + if (this.pipelinePath == null) { + this.pipelinePath = USER_DEFINITION_PIPELINE_PATH; + } return this; } @@ -42,8 +47,18 @@ public void setScriptPath(String scriptPath) { } } + @DataBoundSetter + public void setPipelinePath(String pipelinePath) { + if (StringUtils.isEmpty(pipelinePath)) { + this.pipelinePath = USER_DEFINITION_PIPELINE_PATH; + } else { + this.pipelinePath = pipelinePath; + } + } + public String getScriptPath() { return scriptPath; } + public String getPipelinePath() { return pipelinePath; } public SCM getJenkinsFileScm() { return jenkinsFileScm; @@ -60,7 +75,7 @@ public ConfigDrivenWorkflowBranchProjectFactory() {} @Override protected FlowDefinition createDefinition() { // This creates the CpsScmFlowDefinition... create a new type of "binder"??? // We need a non-hardcoded version of this class... it does almost everything we want already... - return new ConfigFileSCMBinder(scriptPath, jenkinsFileScm); + return new ConfigFileSCMBinder(scriptPath, pipelinePath, jenkinsFileScm); } @Override protected SCMSourceCriteria getSCMSourceCriteria(SCMSource source) { @@ -109,4 +124,4 @@ public Collection> getApplicableDescriptors() { } } -} \ No newline at end of file +} diff --git a/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory.java b/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory.java index d61aad3..e45aa65 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory.java @@ -18,6 +18,8 @@ import java.util.Collection; import static org.jenkinsci.plugins.workflow.multibranch.template.ConfigDrivenWorkflowBranchProjectFactory.USER_DEFINITION_PATH; +import static org.jenkinsci.plugins.workflow.multibranch.template.ConfigDrivenWorkflowBranchProjectFactory.USER_DEFINITION_PIPELINE_PATH; + /** * Defines organization folders by {@link WorkflowBranchProjectFactory}. @@ -25,12 +27,17 @@ public class ConfigDrivenWorkflowMultiBranchProjectFactory extends AbstractWorkflowMultiBranchProjectFactory { private String scriptPath = USER_DEFINITION_PATH; + private String pipelinePath = USER_DEFINITION_PIPELINE_PATH; + private SCM jenkinsFileScm = null; public Object readResolve() { if (this.scriptPath == null) { this.scriptPath = USER_DEFINITION_PATH; } + if (this.pipelinePath == null) { + this.pipelinePath = USER_DEFINITION_PIPELINE_PATH; + } return this; } @@ -43,8 +50,18 @@ public void setScriptPath(String scriptPath) { } } + @DataBoundSetter + public void setpipelinePath(String pipelinePath) { + if (StringUtils.isEmpty(pipelinePath)) { + this.pipelinePath = USER_DEFINITION_PIPELINE_PATH; + } else { + this.pipelinePath = pipelinePath; + } + } + public String getScriptPath() { return scriptPath; } + public String getPipelinePath() { return pipelinePath; } public SCM getJenkinsFileScm() { return jenkinsFileScm; @@ -65,6 +82,7 @@ public ConfigDrivenWorkflowMultiBranchProjectFactory() {} private ConfigDrivenWorkflowBranchProjectFactory newProjectFactory() { ConfigDrivenWorkflowBranchProjectFactory workflowBranchProjectFactory = new ConfigDrivenWorkflowBranchProjectFactory(); workflowBranchProjectFactory.setScriptPath(scriptPath); + workflowBranchProjectFactory.setPipelinePath(pipelinePath); workflowBranchProjectFactory.setJenkinsFileScm(jenkinsFileScm); return workflowBranchProjectFactory; } diff --git a/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigFileSCMBinder.java b/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigFileSCMBinder.java index 28cac1e..2bbe34a 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigFileSCMBinder.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/multibranch/template/ConfigFileSCMBinder.java @@ -56,6 +56,7 @@ import static org.jenkinsci.plugins.workflow.multibranch.template.ConfigDrivenWorkflowBranchProjectFactory.PIPELINE_TEMPLATE; import static org.jenkinsci.plugins.workflow.multibranch.template.ConfigDrivenWorkflowBranchProjectFactory.USER_DEFINITION_PATH; +import static org.jenkinsci.plugins.workflow.multibranch.template.ConfigDrivenWorkflowBranchProjectFactory.USER_DEFINITION_PIPELINE_PATH; /** * Checks out the desired version of {@link ConfigDrivenWorkflowBranchProjectFactory#USER_DEFINITION_PATH}. @@ -63,17 +64,22 @@ class ConfigFileSCMBinder extends FlowDefinition { private String scriptPath; + private String pipelinePath; private SCM jenkinsFileScm; public Object readResolve() { if (this.scriptPath == null) { this.scriptPath = USER_DEFINITION_PATH; } + if (this.pipelinePath == null) { + this.pipelinePath = USER_DEFINITION_PIPELINE_PATH; + } return this; } - @DataBoundConstructor public ConfigFileSCMBinder(String scriptPath, SCM jenkinsFileScm) { + @DataBoundConstructor public ConfigFileSCMBinder(String scriptPath, String pipelinePath, SCM jenkinsFileScm) { this.scriptPath = scriptPath; + this.pipelinePath = pipelinePath; this.jenkinsFileScm = jenkinsFileScm; } @@ -163,27 +169,30 @@ public Object readResolve() { } } } + + String jenkinsfilePathString; + if (configContents == null) { - String pipelineTemplateNotFound = - String.format("Could not find a value for %s in %s", PIPELINE_TEMPLATE, scriptPath); - throw new AbortException(pipelineTemplateNotFound); + jenkinsfilePathString = pipelinePath; } else { - String jenkinsfilePathString = + jenkinsfilePathString = ConfigurationValueFinder.findFirstConfigurationValue(configContents, - ConfigDrivenWorkflowBranchProjectFactory.PIPELINE_TEMPLATE); - - build.addAction(new ConfigFileEnvironmentContributingAction(configContents)); - - try (SCMFileSystem scriptFileSystem = SCMFileSystem.of(job, jenkinsFileScm)) { - if (scriptFileSystem != null) { - script = scriptFileSystem.child(jenkinsfilePathString).contentAsString(); - listener.getLogger().println("Obtained " + jenkinsfilePathString); + ConfigDrivenWorkflowBranchProjectFactory.PIPELINE_TEMPLATE); + if(jenkinsfilePathString == null) { + jenkinsfilePathString = pipelinePath; + } + } + build.addAction(new ConfigFileEnvironmentContributingAction(configContents)); - } + try (SCMFileSystem scriptFileSystem = SCMFileSystem.of(job, jenkinsFileScm)) { + if (scriptFileSystem != null) { + script = scriptFileSystem.child(jenkinsfilePathString).contentAsString(); + listener.getLogger().println("Obtained " + jenkinsfilePathString); - } catch (FileNotFoundException exception) { - throw new AbortException(String.format("Could not find file %s", jenkinsfilePathString)); } + + } catch (FileNotFoundException exception) { + throw new AbortException(String.format("Could not find file %s", jenkinsfilePathString)); } if (script != null) { diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory/config.jelly b/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory/config.jelly index 2edaa1f..2e34807 100644 --- a/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory/config.jelly @@ -29,5 +29,9 @@ THE SOFTWARE. + + + + diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory/help-pipelinePath.html b/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory/help-pipelinePath.html new file mode 100644 index 0000000..9baae27 --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowBranchProjectFactory/help-pipelinePath.html @@ -0,0 +1,3 @@ +
+ Relative default location of pipeline_template. +
diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory/config.jelly b/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory/config.jelly index 2edaa1f..2e34807 100644 --- a/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory/config.jelly +++ b/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory/config.jelly @@ -29,5 +29,9 @@ THE SOFTWARE. + + + + diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory/help-pipelinePath.html b/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory/help-pipelinePath.html new file mode 100644 index 0000000..9baae27 --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/workflow/multibranch/template/ConfigDrivenWorkflowMultiBranchProjectFactory/help-pipelinePath.html @@ -0,0 +1,3 @@ +
+ Relative default location of pipeline_template. +