# Part 10: Environment Variables in Pipelines

* * *

### Jenkins CI/CD Series

| Part | Article |
| --- | --- |
| 1 | [Install Jenkins with Docker](https://ask-abhi.com/part-1-install-jenkins-with-docker) |
| 2 | [Creating Your First Jenkins Pipeline](https://ask-abhi.com/part-2-creating-your-first-jenkins-pipeline) |
| 3 | [Jenkins SSH Remote Execution](https://ask-abhi.com/part-3-jenkins-ssh-remote-execution) |
| 4 | [Automating MySQL Backup to AWS S3](https://ask-abhi.com/part-4-automating-mysql-backup-to-aws-s3) |
| 5 | [Making Jenkins Automation Scalable](https://ask-abhi.com/part-5-making-jenkins-automation-scalable) |
| 6 | [Running Ansible from Jenkins](https://ask-abhi.com/part-6-running-ansible-from-jenkins) |
| 7 | [Jenkins Pipeline from GitHub](https://ask-abhi.com/part-7-control-jenkins-pipeline-through-github) |
| 8 | [Multibranch Pipelines](https://ask-abhi.com/part-8-multibranch-pipelines) |
| 9 | [Parameterized Pipelines](https://ask-abhi.com/part-9-parameterized-pipelines) |
| 10 | [Environment Variables in Pipelines](https://ask-abhi.com/part-10-environment-variables-in-pipelines) |

* * *

### 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** `Host` **and the** `directory` **structure to run** `Dockerfiles` **and** `docker-compose.yml` **(Refer to** [**Part 1**](https://ask-abhi.com/part-1-install-jenkins-with-docker)**)**
    

* * *

### Step-by-step implementation

*   **Prepare the code**
    

```typescript
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."**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/cb521024-5c27-44b5-b243-c5c36cc4833a.png align="center")

*   **Paste the code into the** `pipeline script`
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/4659097f-a1f2-4f34-840e-d1e2db00bbb6.png align="center")

*   **Build Now**
    
*   **Now we can see the pipeline using the variables given in the environment block**
    

![](https://cdn.hashnode.com/uploads/covers/6997142f587b14d25b5231b7/2bbc1e60-fdd7-46fb-ba42-7e7596f28b6c.png align="center")

### 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**](https://ask-abhi.com/part-9-parameterized-pipelines)  
➡️ **Next Article:** [Home](https://ask-abhi.com)

* * *

⭐ If you found this article useful, follow **https://ask-abhi.com** for more DevOps tutorials.

* * *
