Build Parameters and Environment Variables
What you'll learn: How to make Jenkins jobs flexible and reusable by accepting input parameters and leveraging environment variables to share data across build steps.
Why Build Parameters Matter
Hard-coded values make Jenkins jobs brittle. If you want to deploy to different environments or build different branches, you'd need separate jobs for each scenario. Build parameters transform a single job into a flexible template that accepts input at runtime—like function arguments in programming.
Think of it like a coffee order form: instead of creating a different form for every possible drink combination, you have one form with checkboxes for size, milk type, and extras.
Defining Build Parameters
In your job configuration, enable "This project is parameterized" and add parameter types:
- String Parameter: Free-text input (e.g., Git branch name)
- Choice Parameter: Dropdown menu (e.g., dev, staging, production)
- Boolean Parameter: Checkbox (e.g., run tests: yes/no)
These appear as $PARAMETER_NAME in shell steps or ${params.PARAMETER_NAME} in Pipeline scripts.
Environment Variables as Data Carriers
Jenkins automatically provides environment variables like $BUILD_NUMBER, $JOB_NAME, and $WORKSPACE. You access them in build steps to create dynamic behavior—file paths, build tags, or conditional logic.
You can also set custom environment variables within build steps to pass data between sequential steps in the same job, acting as a shared clipboard for your build process.
Practical Pattern
A parameterized deployment job might accept ENVIRONMENT (dev/prod) and VERSION parameters, then use them in a shell step:
echo "Deploying version $VERSION to $ENVIRONMENT environment"
Key Takeaway: Build parameters make jobs reusable across scenarios, while environment variables enable dynamic configuration and data sharing between build steps—essential for maintaining flexible, maintainable CI/CD pipelines.