Overview:
- Active choices plugin
- The Active Choices plugin is used in parametrized freestyle Jenkins jobs to create scripted, dynamic, and interactive job parameters. Active Choices parameters can be dynamically updated and can be rendered as combo-boxes, check-boxes, radio buttons, or rich HTML UI widgets.
- There are three types of active parameters:
- Active Choices Parameter (main idea: set parameter values to select for your build jobs)
- Active Choices Reactive Parameter (main idea: parameters selected according to the specified value of the active choice parameter)
- Active Choices Reactive Reference Parameter
- This post shows the usage of the first two parameters
Plugin installation:
To install the plugin go to Manage Jenkins --> Manage Plugins --> Select Available Tab --> Type Active Choices --> Click Install without restart:
Config of active choice parameters:
- Create freestyle project with the following name:
demo-active-reactive-parameter
: - Select Active Choice Parameter:
- Specify
environment
parameter: - Specify the Fallback script:
- Specify Choice Type --> Single Select and enable filters (optional):
- Save the project
- Now go to Build with parameters to see all your configs in action:
Config of active reactive parameters:
- Now to configure reactive parameters go to Configure again and select Active Choices Reactive Parameter
- Set the following configurations:
if (environment.equals("dev")) { return ["develop", "feature"] } else if (environment.equals("test")) { return ["feature"] } else if (environment.equals("prod")) { return ["main", "master"] } else { return ["develop"] }
- Select referenced parameter (active choice parameter name) and enable filtering:
- Add build step:
echo "ENV= $environment" echo "BRANCH= $git_branch"
- Apply the changes
Build:
- Now you can see that
git_branch
parameter reactively chooses its values according to the value of active choiceenvironment
parameter - Build the project and check the parameters:
Notes:
- The 'Fallback Script' configuration option provides alternate parameter value options in case the main Script fails by throwing an Exception
- To make the active choice parameter default add
selected
option:"[parameter_name]:selected"
- To disable the active choice parameter use:
"[parameter_name]:disabled"