How to do a multiselect input in a pipeline

Issue

How to do a multiselect input in a pipeline

Environment

Resolution

If you need to add a multiselect input step inside a Pipeline, our recommendation is to use the Extended Choice Parameter plugin. Here you have an example of how to config inside a pipeline:


import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition

node {
def multiSelect= new ExtendedChoiceParameterDefinition("name", 
            "PT_MULTI_SELECT", 
            "blue,green,yellow,blue", 
            "project name",
            "", 
            "",
            "", 
            "", 
            "", 
            "", 
            "", 
            "", 
            "", 
            "", 
            "", 
            "", 
            "", 
            "blue,green,yellow,blue", 
            "", 
            "", 
            "", 
            "", 
            "", 
            "", 
            "", 
            "", 
            false,
            false, 
            3, 
            "multiselect", 
            ",") 

   def userInput = input  id: 'customID', message: 'Let\'s promote?', ok: 'Release!', parameters:  [multiSelect]


echo "Hello: "+ userInput
}

References

Have more questions?

3 Comments

  • 0
    Avatar
    Puneeth Nanjundaswamy

    This is not useable with blue ocean interface

  • 0
    Avatar
    Adrian Blakey

    Is there any support for multi-select in a declarative pipeline?

  • 0
    Avatar
    Tim Black

    Is there any support for multi-select in a declarative pipeline?

    UPDATE: yes, apparently there is. Through viewing pipeline error codes, browsing stack overflow and eventually, the plugin source code, I see that after installing the plugin, extendedChoice is another valid type you can use in your declarative "parameters {" section, as in:

     

    extendedChoice(name: "favorite_letters",
    type: "PT_CHECKBOX",
    multiSelectDelimiter: " ", // this only defines delimiter used in the output string value, not used for parsing value input, which must be comma-separated!
    value: """a, b, c, d, e, f""",
    defaultValue: "d, f",
    description: "Select your favorite letter(s)"
    )

    There is woefully little documentation, however, on how all the various "type"s of extendedChoice parameters actually work. The best docs I could find was by looking at my pipeline job configuration through the web interface, which of course shows UI for all the possible types:

    ..and their subparams:

    So far, the JSON types look most interesting and extensible. I hope I can figure out how those work without spending the rest of the day sleuthing..

    Edited by Tim Black
Please sign in to leave a comment.