The Extended Choice Parameter plugin is great and I use it in jobs configured via the UI https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin
However, I'm struggling to get it working in a Jenkinsfile
style pipeline script.
It would appear that the Extended Choice Parameter plugin isn't yet fully compatible with Pipeline scripts since Jenkins pipeline-syntax generator creates the following snippet:
parameters([<object of type com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition>])
If I create the parameters manually I get the same behavior as mentioned in https://issues.jenkins-ci.org/browse/JENKINS-32188
org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class
Does anyone know of any workarounds that can get around the issue of ExtendedChoiceParameterDefinition
not using @DataBoundConstructor
?
- Jenkins 2.19.2
- Extended Choice Parameter plugin 0.75
Since April's 2nd, 2019 it's now possible because of this commit: https://github.com/jenkinsci/extended-choice-parameter-plugin/pull/25
You can use it like this for instance:
properties([
parameters([
extendedChoice(
name: 'PROJECT',
defaultValue: '',
description: 'Sélectionnez le projet à construire.',
type: 'PT_SINGLE_SELECT',
groovyScript: valueKeysScript,
descriptionGroovyScript: valueNamesScript
)
])
])
If you want to know every possible parameter you have to refer to the source code.
If you want to know every possible value for the "type" key, have a look at the PT_*
constants.
Here is my workaround for this pb:
https://gist.github.com/jgraglia/44a7443847cff6f0d87387a46c7bb82f
ie : manually instanciate the parameter by declaring all the args
I was able to add a multi checklist parameter to my pipeline with that.
Like mkobit said it is currently not possible to use the extended choice plugin as a build parameter.
What I like to use as a workaround is a construct like the following
timeout(time: 5, unit: TimeUnit.MINUTES) {
def result = input(message: 'Set some values', parameters: [
booleanParam(defaultValue: true, description: '', name: 'SomeBoolean'),
choice(choices: "Choice One\nChoice Two", description: '', name: 'SomeChoice'),
stringParam(defaultValue: "Text", description: '', name: 'SomeText')
]) as Map<String, String>
}
echo "${result.SomeBoolean}, ${result.SomeChoice}, ${result.SomeText}"
And call it in the beginning of my pipeline. You then get asked for these inputs shortly after your build starts.
来源:https://stackoverflow.com/questions/42392247/how-can-i-use-the-extended-choice-parameter-plugin-in-a-jenkins-pipeline-script