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:

  1. 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_NUMBER returns the current build number.

  2. 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_PARAM returns the value of the parameter named "MY_PARAM".

  3. 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.result returns the result of the current build.

  4. pipeline: This global variable represents the current pipeline being executed. It provides access to various pipeline-specific functions and properties. For example, pipeline.builds returns a list of previous builds of the pipeline.

  5. 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.name returns 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.

[1]