Child pages
  • Extensible Choice Parameter plugin
Skip to end of metadata
Go to start of metadata

Plugin Information

View Extensible Choice Parameter on the plugin site for more information.

Older versions of this plugin may not be safe to use. Please review the following warnings before using an older version:

This plugin adds "Extensible Choice" as a build parameter.You can select how to retrieve choices, including the way to share choices among all jobs.

What's this?

This plugin provides a Extensible Choice parameter:

  • When building, the value can be selected with a dropdown like a built-in Choice parameter.
  • The choices can be provided in several ways:
    • Global Choice Parameter: defines choices in the Configure System page.
      • Choices can be shared by multiple jobs.
      • Updating the choices in the Configure System, every job can immediately refer the updated choices.
    • Textarea Choice Parameter: writes choices in a textarea, just like a built-in Choice parameter.
    • System Groovy Script Choice Parameter: runs a System Groovy script to determine the list of choices
    • File Choice Parameter: lists files in a directory.
  • Checking Editable checkbox allows you to specify any value, even one not in the choices.
    • Edited values can be added to the choice used next time automatically by checking "Add Edited Value".
  • You can add a new way to provide choices with Extension Points.

Disabling providers

Some choice providers may cause security issues in your system:

Choice Provider

Security Issue

Note

File Choice Parameter

Any users with project configuration privilege can list files in the OS with the privilege of the OS user Jenkins run with.

Users can do that also with "Execute shell" or "Execute Windows Batch" build step.

You can disable specific providers in system configuration page:

In the above screen, System Groovy Script Choice Parameter (unchecked one) is disabled.

Screenshots

  • "Extensible Choice" is added as a type of build parameters.
  • You can select the way to define choices of the parameter.
    ** A new way to provide choices can be added with Extension Points.
  • Selecting "Textarea Choice Parameter", you can define choices like the built-in Choice parameter.
  • "Global Choice Parameter" enables you to select a set of choices from the ones defined in System Configuration page.
    • Defining in System Configuration page:
    • Select which set of choices to use:
  • "System Groovy Choice Parameter" generate choices with a Groovy script:
  • "File Choice Parameter" enables select a file in a specified directory:
  • You can specify its default value. This is useful with Global Choice Parameter to specify different default values in jobs:
  • Checking "Editable" enables you to input a value not in choices at build time:
    ** Textarea Choice Parameter and Global Choice Parameter provides "Add Edited Value", which automatically adds a value not in the choice list:

Extension point

A new way to provide choices can be added with extending ChoiceListProvider, overriding the following method:

abstract public List<String> getChoiceList()

Issues

Open Issues

To report a bug or request an enhancement to this plugin please create a ticket in JIRA (you need to login or to sign up for an account). Also have a look on How to report an issue

 

Change Log

Version 1.5.0 (Mar 17, 2018)

Version 1.4.2 (Jan 27, 2018)

Version 1.4.1 (Aug 27, 2017)

Version 1.4.0 (Apr 10, 2017)

  • SECURITY FIX: Jenkins Security Advisory 2017-04-10#Extensible Choice Parameter Plugin
    • Groovy scripts run with Script Security Plugin
    • Existing scripts are configured to run in the script sandbox.
    • You might require approve some methods for the sandbox, or configure scripts run without the sandbox and approve scripts.
  • Targets Jenkins >= 1.580.1.
  • The pre-defined variable 'jenkins' is no longer provided.
    • You can get Jenkins instance with jenkins.model.Jenkins.instance instead. Require appropriate approving.

Version 1.3.4 (Jan 28, 2017)

  • Use the top most value if the specified default parameter isn't contained in the choice list.
    • Note: Builds fail if you passed a value not contained in the choice list explicitly (e.g. via Parameterized trigger plugin).

Version 1.3.3 (Oct 22, 2016)

  • FIXED: "Top Most Value" is replaced with an empty value when saved before the job configuration page is completed to be load (JENKINS-37147)

Version 1.3.2 (Aug 23, 2015)

  • Fixed UnsupportedOperationException when Empty Choice is configured for File Choice Parameter (JENKINS-29934)
  • Improved the help of Exclude Pattern of File Choice Parameter.

Version 1.3.1 (Jun 20, 2015)

  • Fixed NPE with "List Files Now" in configuration pages (JENKINS-28841, regression in 1.3.0)

Version 1.3.0 (May 05, 2015)

  • Now you can disable specific providers in system configuration page (JENKINS-27375).
  • Validates parameter names by checking they can be handled by Jenkins core (JENKINS-22222).
  • Fixed "Error: No stapler-class is specified" when saving project configuation with Jenkins 1.610(JENKINS-28046).
    • Dot letters are allowed for variable names with Jenkins > 1.526.
  • Added an empty choice option to FilenameChoiceListProvider (JENKINS-22318).
  • Also accepts $class introduced in Jenkins 1.588 (JENKINS-25403).

Version 1.2.2 (Dec 08, 2013)

  • Added feature to use project in System Groovy Script. JENKINS-17875
  • Added feature to reverse file lists.

Version 1.2.1 (Jun 22, 2013)

  • Added documents for System Groovy Script Choice Parameter.
  • Added "Run the Script Now" Button for System Groovy Script Choice Parameter.

Version 1.2.0 (May 03, 2013)

  • Added new providers
    • System Groovy Script Choice Parameter: runs a System Groovy script to determine the list of choices
    • File Choice Parameter: lists files in a directory.
  • Added checkbox "Add Edited Value" to Textarea Choice Parameter and Global Choice Parameter. By checking this, edited values used in builds are automatically added to choices.

Version 1.1.0 (Feb 06, 2013)

  • Now you can select the default choice in each job.
  • Fixed the misspell.

Version 1.0.0 (Jan 07, 2013)

  • Initial release.

21 Comments

  1. Hi:

    This plugin is real nice.  I need a bit of clarification.  I am using the System Groovy Choice Parameter option.  I wrote a small fragment of groovy script to populate a list of parameter choices.

    It works fine, no problem.

    However if I want to read a first parameter and based on that I want the groovy script to build a diff list each time for the second parameter.  Is this eve possible and if so how do we do that ?

    Thank You for your time and attention.

    -Narahari

    1. Unfortunately, this plugin does not support that feature.
      This plugin generates choices only once when displaying the building page.

  2. Unknown User (jl.pinardon)

    Hi,

    Interesting plugin, but I think it lacks a very simple feature : get the choices from a file.
    Simply configure a file path and the plugin gets each line as a choice item.

    I guess it can be easily scripted using a groovy script, but not all build managers are groovy skilled.

    Best Regards and thanks for your help and attention.
    J.L.P.

  3. The file choice option is great, thanks!  As a suggestion, it would be nice if the default can be set to a blank or something similar.  The way it is now, it's too easy for a user to select the default (first file) inadvertently

  4. Great plugin but is there an option for multi-select? With so many ways of generating the selectable options, I think that this plugin would be the best in supporting this need. Thank you! 

  5. After the parameterized trigger plugin is doing a type-check we have to use this plugin too. Nice :-) But the switch of type is not as easy as i thougt.

    Please can you have a look at issue 22222? The is no default-assignee so i also write it here in the commons.

    Thank you.

  6. Hi ikedam,

                        thanks a lot for build really nice plugin,just to check are you thinking of enhancing this plugin to support populating the list based on selection of other list.

    thanks

    Prithvi

    1. I don't plan that extension.
      Extensible choice parameter generates choices when displaying a build parameter page, and cannot update choices after displaying the page.

  7. Thanks for this great plugin.  As an example of how to use it with a Groovy script -- and how to use it to replace the odd Git Parameter Plugin -- I posted this to my blog:

    Jenkins and Git at Plaid Speed

  8. Question about the plugin.  Is there a way to know what the WORKSPACE folder is, inside of the plugin groovy script.

    I want to be able to do 

    def x=$WORKSPACE

    But is $WORKSPACE going to get resolved at plugin time or build time ?

  9. No, you can never get WORKSPACE in your script as Jenkins doesn't decide where to run the build yet.

  10. Hi, was testing this plugin in the lates jenkins release and got the "no stapler-class is specified" error. I tried to fix this by changing

    ExtensibleChoiceParameterDefinition.java ">ExtensibleChoiceParameterDefinition.java 

    to use class instead of stapler-class. This did not work, do I have to make additional changes to the jelly files as well?">to use class instead of stapler-class. This did not work, do I have to make additional changes to the jelly files as well?

    my change:

          

          String staplerClazzName = formData.optString("$class", null);
    
                if (staplerClazzName == null) {
    
                    staplerClazzName = formData.optString("stapler-class", null);
    
                }
    
    
    
                if (staplerClazzName == null) {
    
                    throw new FormException("No $class or stapler-class is specified", fieldName);
    
                }
    

                String staplerClazzName = formData.optString("$class", null);
                if (staplerClazzName == null)

    Unknown macro: {                staplerClazzName = formData.optString("stapler-class", null);            }

                if (staplerClazzName == null)

    Unknown macro: {                throw new FormException("No $class or stapler-class is specified", fieldName);            }
    1. Thanks for the report.
      That looks related to JENKINS-25403.
      I think your change works well.

      I'm planning to make a new release in a month and will fix it in that release.

      You might consider to use the LTS Jenkins release instead of the latest one if you don't want to use the modified extensible-choice-parameter and you don't need new features in the latest Jenkins.

  11. We currently have several projects that use the same exact "Groovy System Script", that we have to copy-paste into each project. Is it possible to define a global script somehow, and reference it in each project?

  12. One more question: Is it possible to define a default file for the File Choice Parameter? Currently it selects the first one in the list, and it seems to be sorted alphabetically.

    Great plugin by the way :)

  13. Example to generates password. (Dynamic Parameter -> Default Value Script)

    import org.apache.commons.lang.RandomStringUtils
    
    String charset = (('a'..'z') + ('0'..'9')).join()
    Integer length = 10
    String randomString = RandomStringUtils.random(length, charset.toCharArray())
    return randomString
    return randomString
    
  14. Will execute work? e.g.

    ("git tag".execute()).text.split('\n').collect{it as String}
    
  15. If you want to access to ParametersName of the build :

    (don't forget the import)

    import hudson.model.*
    def toReturn=[]
    toReturn.add(binding.project.properties)
    //toReturn.add(binding.project.getProperty('PROJECT_SVN_URL'))
    toReturn.add(binding.project.getProperty(ParametersDefinitionProperty.class))
    toReturn.add(binding.project.getProperty('EnvInjectJobProperty'))
    toReturn.add(binding.project.lastBuild.id)
    //toReturn
    //binding.project.getProperty('EnvInjectJobProperty')
    binding.project.getProperty(ParametersDefinitionProperty.class).parameterDefinitions.each(){
       toReturn.add( it.name );
    }
    toReturn

    import hudson.model.*
    def toReturn=[]
    binding.project.getProperty(ParametersDefinitionProperty.class).parameterDefinitions.each(){
       toReturn.add( it.name );
    }
    toReturn
    
    1. sorry for double code snippet, just use the second one

  16. What is the difference between this plugin and Extended Choice Parameter plugin ?

  17. I am using Extensible Choice Parameter for my build. And my requirement is to trigger D.sh which is inside A/B/C/D.sh. Now i want to select D.sh through my input. So i added three File Choice Parameter and i am facing issue of passing the value of first parameter to the input of second parameter

    Variable-1 : AAA and its Base directory is /tmp/A

    Variable-2 : BBB and its Base Directory is /tmp/$

    Unknown macro: {AAA}

     --- Not Working as it couldnt understand $

     whereas if i hardcode with actual value (/tmp/A) then it is working absolutely fine.

    Variable-3 : CCC and its Base Directory is /tmp/$

    Unknown macro: {AAA}

    /

    Unknown macro: {BBB}

     --- Not Working as it couldnt understand $

    & $

    Unknown macro: {BBB}

    whereas if i hardcode with actual value (/tmp/A/B/C) then it is working absolutely fine.

    I am struck on this. please help with your inputs.

Write a comment…