How do I set a default choice in jenkins pipeline? How do I set a default choice in jenkins pipeline? jenkins jenkins

How do I set a default choice in jenkins pipeline?


You can't specify a default value in the option. According to the documentation for the choice input, the first option will be the default.

The potential choices, one per line. The value on the first line will be the default.

You can see this in the documentation source, and also how it is invoked in the source code.

return new StringParameterValue(  getName(),   defaultValue == null ? choices.get(0) : defaultValue, getDescription());


As stated by mkobit it doesn't seem possible with the defaultValue parameter, instead I reordered the list of choices based on the previous pick

defaultChoices = ["foo", "bar", "baz"]choices = createChoicesWithPreviousChoice(defaultChoices, "${params.CHOICE}")properties([    parameters([        choice(name: "CHOICE", choices: choices.join("\n"))    ])   ])node {    stage('stuff') {        sh("echo ${params.CHOICE}")    }}List createChoicesWithPreviousChoice(List defaultChoices, String previousChoice) {    if (previousChoice == null) {       return defaultChoices    }    choices = defaultChoices.minus(previousChoice)    choices.add(0, previousChoice)    return choices}


Another option is using extendedChoice parameter of type PT_RADIO. It supports setting default values.

You'd have to install this plugin

extendedChoice description: '', multiSelectDelimiter: ',', name: 'PROJ_NAME',                quoteValue: false, saveJSONParameterToFile: false, type: 'PT_RADIO',                value: 'a,b', visibleItemCount: 2, defaultValue: 'a'

It looks like below:

enter image description here