JENKINS - Build In Variables
Jenkins provides a variety of built-in environment variables that can be used in your Jenkins Pipelines to access information about the build environment, the build process, and the system. Here is a comprehensive list of the most commonly used built-in environment variables, along with their descriptions:
Common Built-in Jenkins Environment Variables
BUILD_ID- Description: A unique identifier for the current build. It is the same as
BUILD_NUMBER. - Example:
2024
- Description: A unique identifier for the current build. It is the same as
BUILD_NUMBER- Description: The current build number, which is an incrementing integer starting from 1.
- Example:
42
BUILD_DISPLAY_NAME- Description: The display name of the current build, often including the build number.
- Example:
#42
BUILD_TAG- Description: A unique identifier for the current build in the format
job_name_build_number. - Example:
jenkins-MyJob-42
- Description: A unique identifier for the current build in the format
BUILD_URL- Description: The URL to the build's web page.
- Example:
http://localhost:8080/job/MyJob/42/
JOB_NAME- Description: The name of the job being executed.
- Example:
MyJob
JOB_BASE_NAME- Description: The base name of the job, without the folder path.
- Example:
MyJob
JOB_URL- Description: The URL to the job's web page.
- Example:
http://localhost:8080/job/MyJob/
WORKSPACE- Description: The absolute path of the workspace directory assigned to the build.
- Example:
/var/lib/jenkins/workspace/MyJob
NODE_NAME- Description: The name of the node (agent) on which the current build is running. For the master node, this is
"master". - Example:
slave1
- Description: The name of the node (agent) on which the current build is running. For the master node, this is
NODE_LABELS- Description: A space-separated list of labels assigned to the node.
- Example:
linux docker
EXECUTOR_NUMBER- Description: The unique number that identifies the current executor.
- Example:
0
JENKINS_HOME- Description: The path to the Jenkins home directory.
- Example:
/var/lib/jenkins
JENKINS_URL- Description: The URL to the Jenkins instance.
- Example:
http://localhost:8080/
JENKINS_SERVER_COOKIE- Description: A unique identifier for the Jenkins server, used to avoid cross-server CSRF issues.
- Example:
b83a3cfc
GIT_COMMIT- Description: The commit hash of the current Git revision.
- Example:
a1b2c3d4
GIT_BRANCH- Description: The name of the Git branch currently being built.
- Example:
main
GIT_URL- Description: The URL of the Git repository.
- Example:
https://github.com/example/repo.git
SVN_REVISION- Description: The Subversion revision number of the build.
- Example:
1234
SVN_URL- Description: The URL of the Subversion repository.
- Example:
http://svn.example.com/repo
BRANCH_NAME- Description: The name of the branch being built (often used in Multibranch Pipeline jobs).
- Example:
feature-branch
Example of Using Environment Variables in a Jenkins Declarative Pipeline
Here is an example Jenkins Declarative Pipeline that prints out some of these environment variables:
pipeline {
agent any
stages {
stage('Print Environment Variables') {
steps {
script {
echo "BUILD_ID: ${env.BUILD_ID}"
echo "BUILD_NUMBER: ${env.BUILD_NUMBER}"
echo "JOB_NAME: ${env.JOB_NAME}"
echo "WORKSPACE: ${env.WORKSPACE}"
echo "NODE_NAME: ${env.NODE_NAME}"
echo "JENKINS_URL: ${env.JENKINS_URL}"
echo "GIT_COMMIT: ${env.GIT_COMMIT}"
echo "GIT_BRANCH: ${env.GIT_BRANCH}"
echo "BRANCH_NAME: ${env.BRANCH_NAME}"
}
}
}
}
}
Comments
Post a Comment