Hi All, this document shows how to use the choice parameter variable in the Jenkins pipeline.
Jenkins is a widely used CICD tool that supports a lot of integrations. There are certain use cases to have choice based parameter variables for Jenkins Job. Some cases will be to have true or false variables in other cases you will have options like 1, 2, 3. This allows the user who runs Jenkins’s job will have predefined options as a parameter rather than entering the inputs.
One simple use case if you are using a single Jenkins job for deploying multiple environments, where you will have a conditional statement to pick which environment the build needs to be moved. In this case, We can choose the choice parameter in which the user selects the environment rather than entering as a variable. There a lot of chances the job to get failed when the parameters come as case sensitive. Either job should be written in a way that handles the case sensitivity.
Another parameter that can be used in a boolean parameter which accepts true or false. Let’s say do you need a backup before deploying the build. This is one use case to choose the boolean parameter.
Based on the above-mentioned use cases I have created a sample pipeline that takes choice based parameters.
Below are the screenshots of Build with parameters.
Here you can see a drop-down option to select the environment.
With Blue ocean
In the Blue ocean theme, you can exactly see the option.
For your Jenkins job you can use the below-mentioned parameter, which can be changed as per your requirement.
Below is the sample Jenkins job.
© 2020, Techrunnr. All rights reserved.