Search code examples
jenkinsjenkins-pipeline

In Jenkins pipeline, how can I make a choice parameter list editable?


I have the following pipeline Jenkinsfile code that presents the user with a drop-down list.

properties ([
  disableConcurrentBuilds(),
  parameters ([
    choiceParam(name: "PICK_A_NUMBER",
                choices: [0, 1, 2, 3],
                description: "Simple choice")
  ])
])

How can I make it editable so the user can enter a different choice from the ones presented? Thanks!


Solution

  • There is an existing plugin called Editable Choice Plugin which provides an editable choice parameter feature which is exactly what you are looking for, the plugin enables you to select a value from a list of choices, or alternatively you can input any custom value, even if does not appear in the choice list.

    Usage is quite simple:

    pipeline {
      agent any
      parameters {
        editableChoice(
          name: 'PARAM1',
          choices: ['Apple', 'Grape', 'Orange'],
        )
      }
      stages {
        stage('build') {
          steps {
            echo "PARAM1=${params.PARAM1}"
           }
        }
      }
    }
    

    It also supports a default value option, an optional parameter to restrict the input to the choice list and a suggestions like filter config mechanism for displaying specific options.