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?
You just have to use params. [NAME] in places where you need to substitute the parameter. Here is an example of a stage that will be executed based on the condition that we get from the choice parameter. The parameter name is ENVIRONMENT , and we access it in the stage as params.
Using build parameters, we can pass any data we want: git branch name, secret credentials, hostnames and ports, and so on. Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.
To install this plugin, you simply need to go to your jenkins instance and navigate to “/pluginManager/available”, and then search for “Extended Choice Parameter Plug-in” in the search box. Be careful! There is another plugin called “Extensible Choice Parameter Plug-in”.
The documentation for declarative jenkins pipelines says:
A choice parameter, for example:
pipeline {
.....
parameters {
choice(name: 'CHOICES', choices: ['one', 'two', 'three'], description: '') }
First one is the default value
You need to use \n
instead of \
.
See this code:
pipeline {
agent any
parameters {
choice(
name: 'myParameter',
choices: "Option1\nOption2",
description: 'interesting stuff' )
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With