How to Configure Build Parameters in Jenkins Easily
To configure build parameters in Jenkins, enable the
Parameterized Build option in your job settings and add parameters like String, Boolean, or Choice. These parameters let you input values before running a build, making your jobs flexible and reusable.Syntax
In Jenkins, build parameters are configured in the job's configuration page under the General section by enabling This project is parameterized. You then add parameters with types such as:
String Parameter: Accepts text input.Boolean Parameter: A true/false checkbox.Choice Parameter: Dropdown list of options.
Each parameter has a Name and Default Value or Choices depending on type.
groovy
parameters {
string(name: 'BRANCH', defaultValue: 'main', description: 'Git branch to build')
booleanParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?')
choice(name: 'ENV', choices: ['dev', 'staging', 'prod'], description: 'Deployment environment')
}Example
This example shows how to configure build parameters in a Jenkins Pipeline script. It defines a string, boolean, and choice parameter. When you run the job, Jenkins will ask for these inputs.
groovy
pipeline {
agent any
parameters {
string(name: 'BRANCH', defaultValue: 'main', description: 'Git branch to build')
booleanParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests?')
choice(name: 'ENV', choices: ['dev', 'staging', 'prod'], description: 'Deployment environment')
}
stages {
stage('Build') {
steps {
echo "Building branch: ${params.BRANCH}"
echo "Run tests: ${params.RUN_TESTS}"
echo "Deploying to environment: ${params.ENV}"
}
}
}
}Output
Building branch: main
Run tests: true
Deploying to environment: dev
Common Pitfalls
Common mistakes when configuring build parameters include:
- Not enabling
This project is parameterizedbefore adding parameters. - Using parameter names that do not match in the pipeline script (case sensitive).
- Forgetting to reference parameters with
params.PARAM_NAMEin pipeline scripts. - Setting default values that do not match expected input types.
groovy
pipeline {
agent any
parameters {
string(name: 'branch', defaultValue: 'main', description: 'Git branch')
}
stages {
stage('Build') {
steps {
// Wrong: using uppercase 'BRANCH' instead of 'branch'
echo "Building branch: ${params.BRANCH}"
// Right:
echo "Building branch: ${params.branch}"
}
}
}
}Quick Reference
| Parameter Type | Description | Usage Example |
|---|---|---|
| String Parameter | Text input from user | string(name: 'VERSION', defaultValue: '1.0', description: 'Version to build') |
| Boolean Parameter | True/False checkbox | booleanParam(name: 'DEPLOY', defaultValue: false, description: 'Deploy after build?') |
| Choice Parameter | Dropdown list of options | choice(name: 'ENV', choices: ['dev', 'qa', 'prod'], description: 'Select environment') |
Key Takeaways
Enable 'This project is parameterized' in Jenkins job settings to add build parameters.
Use parameter types like String, Boolean, and Choice to customize input.
Access parameters in pipeline scripts with 'params.PARAM_NAME' syntax.
Ensure parameter names match exactly between configuration and script.
Set meaningful default values to simplify build runs.