Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-50125 Add DefaultParametersAction to triggered job.
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../groovy/com/ceilfors/jenkins/plugins/jiratrigger/parameter/DefaultParametersAction.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.ceilfors.jenkins.plugins.jiratrigger.parameter | ||
|
||
import hudson.model.Job | ||
import hudson.model.ParameterValue | ||
import hudson.model.ParametersAction | ||
import hudson.model.ParametersDefinitionProperty | ||
|
||
/** | ||
* <tt>DefaultParametersAction</tt> is required because we are using <tt>ParametersAction</tt> | ||
* in <tt>ParametersMappingAction</tt>. The default values of a parameterised job is only | ||
* automatically populated by ParameterizedJobMixIn.scheduleBuild2 when <tt>ParametersAction</tt> | ||
* absent from the scheduled actions. The proper solution is to use <tt>EnvironmentContributingAction</tt> | ||
* instead of <tt>ParametersMappingAction</tt>, but unfortunately this solution is not viable due to JENKINS-46482. | ||
* | ||
* Generating default values by ourselves (instead of relying on #scheduleBuild2) seems to be a common solution in | ||
* the community. Example: https://github.com/jenkinsci/ghprb-plugin/blob/c15d5106e78f7f028c6305dccf01b77cc9a724b3/ | ||
* src/main/java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java#L386 | ||
* | ||
* @author ceilfors | ||
*/ | ||
class DefaultParametersAction extends ParametersAction { | ||
|
||
DefaultParametersAction(Job job) { | ||
super(getDefaultParameters(job)) | ||
} | ||
|
||
private static List<ParameterValue> getDefaultParameters(Job job) { | ||
ParametersDefinitionProperty pdp = job.getProperty(ParametersDefinitionProperty) | ||
pdp != null ? pdp.parameterDefinitions*.defaultParameterValue : [] | ||
} | ||
} |