Part 10: Environment Variables in Pipelines
Make it variables and reusable

Jenkins CI/CD Series
Goal
Understand how to use environment variables in Jenkins pipelines
Define variables at:
Global level
Pipeline level
Stage level
Use environment variables to control pipeline behavior dynamically
Learn how to manage sensitive data securely
Purpose
The purpose of this part is to make your pipelines configurable, reusable, and secure.
So far, you have:
Static pipelines
Parameterized inputs
But real-world pipelines require:
Managing configuration like URLs, ports, and credentials
Handling different environments (Dev, UAT, Prod)
Avoiding hardcoding sensitive data in scripts
Environment variables help you:
Centralize configuration
Reuse pipelines across environments
Improve maintainability and readability
This is a core DevOps practice used in:
CI/CD pipelines
Kubernetes deployments
Cloud-native applications
Prerequisite
Before starting this part, ensure:
- Ready to use
Hostand thedirectorystructure to runDockerfilesanddocker-compose.yml(Refer to Part 1)
Step-by-step implementation
- Prepare the code
pipeline {
agent any
environment {
def myString = "Hello World"
def myNumber = 10
def myBool = true
}
stages{
stage("Demo") {
steps {
echo "myString: ${myString}"
echo "myNumber: ${myNumber}"
echo "myBool: ${myBool}"
}
}
}
}
- Create pipeline "variable-jenkins."
- Paste the code into the
pipeline script
Build Now
Now we can see the pipeline using the variables given in the environment block
Done!!!
Conclusion
In this part, you upgraded your pipeline to a fully configurable and production-ready CI/CD system
You learned how to:
Use environment variables effectively in pipelines
Avoid hardcoding values
Manage configurations across environments
Improve pipeline reusability and security
This is how modern DevOps pipelines are designed:
Flexible across environments
Secure with proper secret handling
Easy to maintain and scale
🔚 Final Note (Series Completion)
🎉 Congratulations! we have completed the Jenkins CI/CD Mastery Series
We have built:
End-to-end CI/CD pipelines
Scalable automation workflows
Production-ready DevOps practices
🔗 Continue the Series
⬅️ Previous Article: Part 9 Parameterized Pipelines
➡️ Next Article: Home
⭐ If you found this article useful, follow https://ask-abhi.com for more DevOps tutorials.





