0
0
Jenkinsdevops~10 mins

Dynamic parameter values in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Dynamic parameter values
Start Job
Display Parameters
User selects parameter
Parameter triggers dynamic update?
NoUse default/static value
Yes
Fetch new parameter values dynamically
Update parameter options
User confirms selections
Run Job with selected parameters
The job starts by showing parameters. If a parameter triggers dynamic updates, new values are fetched and options updated before running the job.
Execution Sample
Jenkins
properties([
  parameters([
    choice(name: 'ENV', choices: ['dev', 'qa', 'prod'], description: 'Select environment'),
    choice(name: 'VERSION', choices: getVersions(params.ENV), description: 'Select version')
  ])
])
This Jenkins pipeline snippet shows how the 'VERSION' parameter choices depend dynamically on the selected 'ENV' parameter.
Process Table
StepActionParameterValue/ChoicesResult
1Start job--Parameters displayed with ENV choices ['dev', 'qa', 'prod'] and VERSION empty
2User selects ENVENVdevTrigger dynamic update for VERSION
3Fetch versions for ENV=devVERSION['1.0', '1.1', '1.2']VERSION choices updated
4User selects VERSIONVERSION1.1Parameter selection complete
5Run job with parametersENV, VERSIONdev, 1.1Job executes with selected parameters
6User changes ENVENVprodTrigger dynamic update for VERSION
7Fetch versions for ENV=prodVERSION['2.0', '2.1']VERSION choices updated
8User selects VERSIONVERSION2.0Parameter selection complete
9Run job with parametersENV, VERSIONprod, 2.0Job executes with updated parameters
💡 Job runs after user selects parameters and dynamic values are updated accordingly.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 6After Step 7Final
ENVnulldevdevprodprodprod
VERSION choices[][]['1.0', '1.1', '1.2']['1.0', '1.1', '1.2']['2.0', '2.1']['2.0', '2.1']
VERSION selectednullnull1.11.11.12.0
Key Moments - 2 Insights
Why does the VERSION parameter choices change after selecting ENV?
Because VERSION depends on ENV, selecting ENV triggers fetching new VERSION choices dynamically as shown in steps 2 and 3 of the execution table.
What happens if the user changes ENV after selecting VERSION?
Changing ENV again triggers a dynamic update of VERSION choices (steps 6 and 7), so the previously selected VERSION may no longer be valid and must be reselected.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what are the VERSION choices after the user selects ENV as 'dev'?
A['1.0', '1.1', '1.2']
B['2.0', '2.1']
C['dev', 'qa', 'prod']
D[]
💡 Hint
Check step 3 in the execution table where ENV is 'dev' and VERSION choices are updated.
At which step does the job run with ENV='prod' and VERSION='2.0'?
AStep 5
BStep 7
CStep 9
DStep 3
💡 Hint
Look for the step where parameters ENV='prod' and VERSION='2.0' are used to run the job.
If the user never changes ENV, what happens to VERSION choices after step 1?
AThey default to ['2.0', '2.1']
BThey remain empty
CThey update dynamically
DThey default to ['1.0', '1.1', '1.2']
💡 Hint
Refer to the variable_tracker and execution_table steps before ENV selection triggers updates.
Concept Snapshot
Dynamic Parameter Values in Jenkins:
- Parameters can depend on others.
- Selecting one parameter triggers update of dependent parameter choices.
- Use functions to fetch dynamic choices based on current selections.
- Job runs only after user confirms all parameters.
- Helps customize builds based on user input dynamically.
Full Transcript
This visual execution shows how Jenkins handles dynamic parameter values. The job starts by displaying parameters. When the user selects the ENV parameter, it triggers fetching new choices for the VERSION parameter dynamically. The user then selects a VERSION from updated options. The job runs with these selected parameters. If the user changes ENV again, VERSION choices update accordingly, requiring reselection. This process ensures parameters adapt dynamically based on user input before the job runs.