-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a default template path for when we can't find a pipeline_template #195
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,24 +56,30 @@ | |
|
||
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}. | ||
*/ | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if adding a log entry here might be useful and perhaps providing a different What I'm thinking is that it might be hard to tell which of these code branches the plugin has taken and whether I have a misconfiguration in the plugin or if my repo simply isn't correct. Basically, seems like it'd be nice to help the user and admin understand. Perhaps we could log whether the Config File was found, whether |
||
} 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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,5 +29,9 @@ THE SOFTWARE. | |
<f:entry title="${%Config File Path}" field="scriptPath"> | ||
<f:textbox default=".yourconfig.yml"/> | ||
</f:entry> | ||
<f:entry title="${%Pipeline Template Path}" field="pipelinePath"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if |
||
<f:textbox default="Jenkinsfile"/> | ||
</f:entry> | ||
|
||
<f:dropdownDescriptorSelector field="jenkinsFileScm" title="Centralized Jenkinsfile SCM" descriptors="${descriptor.applicableDescriptors}"/> | ||
</j:jelly> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,3 @@ | ||||||
<div> | ||||||
Relative default location of pipeline_template. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be good to describe the example. It doesn't have to be this suggestion but maybe something like this:
Suggested change
|
||||||
</div> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,3 @@ | ||||||
<div> | ||||||
Relative default location of pipeline_template. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same suggestion as above 😄
Suggested change
|
||||||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on whether we go with the name change for the field, it might be good to name this closer to what it is. 😄