Overview
The Jenkins pipeline uses environment variables to manage Docker image naming and other configuration settings. These variables are defined in theenvironment block of the Jenkinsfile.
Pipeline Environment Variables
The name of the Docker image to build and deploy. This variable is used throughout the pipeline stages for building and running the container.Usage in pipeline:
- Build stage:
docker build -t $IMAGE_NAME:latest . - Deploy stage:
docker run --name Jenkins -d -p 80:3000 $IMAGE_NAME:latest
Configuration Example
Here’s how environment variables are configured in the Jenkinsfile:Adding Custom Environment Variables
To add additional environment variables to your pipeline:- Open the
Jenkinsfilein your repository - Add variables to the
environmentblock:
- Reference variables in your pipeline stages using
$VARIABLE_NAMEsyntax
Best Practices
- Use descriptive variable names that clearly indicate their purpose
- Store sensitive data (credentials, API keys) using Jenkins Credentials instead of plain environment variables
- Document all custom environment variables in your project documentation
- Use consistent naming conventions (uppercase with underscores)