Search code examples
jenkinsjenkins-pipeline

Defining custom variables on Jenkins pipeline


I want to run a command like below on "Execute shell" section,

./test.sh --model Toyota --year 2000

So I want define variables on the pipeline config page and use this variables on the command above like this;

./test.sh --model $car --year $year

There should be a "car" and "year" dropdown menu or a textbox on the pipeline page and when user selects any car or year, these selection will be used in the command above.

Any idea how can I do that?


Solution

  • You would need to add a parameters directive at the pipeline scope:

    parameters {
      string(name: 'car',
        description: 'The car name.')
      string(name: 'year',
        description: 'The car year.')
    }
    

    and then access within the params object:

    ./test.sh --model $params.car --year $params.year