0
0
Jenkinsdevops~10 mins

Parameterized builds in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Parameterized builds
Start Build
Prompt for Parameters
User Inputs Values
Build Uses Parameters
Build Executes with Inputs
Build Completes with Results
The build starts by asking for input parameters, then uses those inputs during the build execution, and finally completes with results based on those inputs.
Execution Sample
Jenkins
pipeline {
  agent any
  parameters {
    string(name: 'GREETING', defaultValue: 'Hello', description: 'Greeting message')
  }
  stages {
    stage('Say Hello') {
      steps {
        echo "${params.GREETING}, Jenkins!"
      }
    }
  }
}
This Jenkins pipeline asks for a greeting message and then prints it during the build.
Process Table
StepActionParameter ValueBuild Output
1Build starts and prompts for GREETINGNo value yetWaiting for input
2User inputs GREETING='Hi there'Hi thereReady to run build
3Build runs stage 'Say Hello'Hi therePrints: Hi there, Jenkins!
4Build completesHi thereBuild success
💡 Build finishes after using the parameter value in the echo step
Status Tracker
VariableStartAfter Step 2After Step 3Final
params.GREETINGundefinedHi thereHi thereHi there
Key Moments - 2 Insights
Why does the build ask for GREETING before running?
Because the parameter is defined in the 'parameters' block, Jenkins pauses to get user input before executing the build steps, as shown in execution_table step 1 and 2.
What happens if no input is given for GREETING?
The build uses the default value 'Hello' defined in the parameter, so the output would be 'Hello, Jenkins!' instead of a user input, as implied by the defaultValue in the code.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the parameter value at step 3?
A"Hello"
Bundefined
C"Hi there"
Dnull
💡 Hint
Check the 'Parameter Value' column at step 3 in the execution_table
At which step does the build print the greeting message?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Build Output' column to find when the message is printed
If the user inputs no value, what will the build output be?
A"Hello, Jenkins!"
B"Hi there, Jenkins!"
C", Jenkins!"
DBuild fails
💡 Hint
Refer to the defaultValue in the parameters block in the execution_sample code
Concept Snapshot
Jenkins Parameterized Builds:
- Define parameters in 'parameters' block
- Jenkins prompts user before build starts
- Use parameters via 'params.PARAM_NAME'
- Default values used if no input given
- Enables flexible, reusable builds
Full Transcript
Parameterized builds in Jenkins let you ask users for input before running a build. You define parameters in the pipeline code, like a string parameter named GREETING with a default value. When the build starts, Jenkins pauses and asks for the GREETING value. The user types a message, for example 'Hi there'. The build then uses this input in its steps, printing the greeting message. If the user does not provide input, the default value is used. This makes builds flexible and customizable without changing code.