jenkins pipeline global variables define and usage
Jenkins Pipeline Global Variables: Definition and Usage
Jenkins Pipeline provides a set of global variables that can be used in Jenkinsfiles to access information about the Jenkins environment and perform various operations. These global variables are predefined and can be used without explicitly declaring them. Here is an overview of some commonly used Jenkins Pipeline global variables:
env: This global variable provides access to environment variables defined in Jenkins. It can be used to access information such as the current workspace, build number, and build URL. For example,
env.BUILD_NUMBERreturns the current build number.
params: This global variable provides access to build parameters defined in Jenkins. It can be used to retrieve parameter values passed to the Jenkins job. For example,
params.MY_PARAMreturns the value of the parameter named "MY_PARAM".
currentBuild: This global variable represents the current build being executed. It provides access to information about the build, such as its status, duration, and result. For example,
currentBuild.resultreturns the result of the current build.
pipeline: This global variable represents the current pipeline being executed. It provides access to various pipeline-specific functions and properties. For example,
pipeline.buildsreturns a list of previous builds of the pipeline.
stage: This global variable represents the current stage being executed in the pipeline. It provides access to information about the stage, such as its name and status. For example,
stage.namereturns the name of the current stage.
These are just a few examples of the global variables available in Jenkins Pipeline. There are many more global variables that can be used to access and manipulate Jenkins-related information. For a comprehensive list of global variables, you can refer to the Jenkins documentation or the Jenkins Pipeline Syntax page.