Search code examples
jenkins-pipeline

Jenkins: How to use choice parameter in declarative pipeline?


My example:

pipeline {
  agent any
  parameters {
    choice(
        name: 'myParameter',
        choices: "Option1\Option2",
        description: 'interesting stuff' )
  }
}

outputs with error:

"  unexpected char: '\'  " on the line with "choices" "

Following these instructions: https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Parametrized-pipelines

Any idea or advice on what I do wrong?


Solution

  • You need to use \n instead of \. See this code:

      pipeline {
      agent any
      parameters {
        choice(
            name: 'myParameter',
            choices: "Option1\nOption2",
            description: 'interesting stuff' )
      }
    }