Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use the Extended Choice Parameter plugin in a Jenkins pipeline script?

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
like image 425
Spangen Avatar asked Feb 22 '17 13:02

Spangen


People also ask

How do I add extended choice parameters in Jenkins?

To install this plugin, you simply need to go to your jenkins instance and navigate to “/pluginManager/available”, and then search for “Extended Choice Parameter Plug-in” in the search box. Be careful! There is another plugin called “Extensible Choice Parameter Plug-in”.

How Jenkins parameter is used in pipeline script?

You just have to use params. [NAME] in places where you need to substitute the parameter. Here is an example of a stage that will be executed based on the condition that we get from the choice parameter. The parameter name is ENVIRONMENT , and we access it in the stage as params.


1 Answers

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.

like image 66
DevAntoine Avatar answered Sep 20 '22 15:09

DevAntoine