当前位置:网站首页>Devops integration - environment variables and building tools of Jenkins service

Devops integration - environment variables and building tools of Jenkins service

2022-04-23 19:30:00 Lao wa next door

One 、 environment variable

Environment variables can be seen as pipeline And Jenkins An interactive medium . such as , Can be in pipeline Pass through BUILD_NUMBER The variable knows the current number of builds for the build task . Environment variables can be divided into Jenkins Built in variables and custom variables .

1.1、Jenkins Built-in variables

stay pipeline Execution time ,Jenkins Through a named env Global variable of , take Jenkins The built-in environment variables are exposed .
Default env The properties of can be directly in pipeline I quote ; There are three ways to quote :

  1. ${env.BUILD_NUMBER} Mode one , Recommended
  2. $env.BUILD_NUMBER Mode two ,
  3. ${BUILD_NUMBER} Mode three , It is not recommended to use

Let's briefly introduce some variables that are often used in practical work .

  1. BUILD_NUMBER: Construction number , Cumulative number .
  2. BRANCH_NAME: Multiple branches pipeline Project support .
  3. BUILD_URL: The currently built page URL.
  4. GIT_BRANCH: adopt git This variable is only available for projects built from the pulled source code .

1.2、 Customize Pipeline environment variable

When pipeline When it gets complicated , We will have the need to define our own environment variables . declarative pipeline Provides environment Instructions , Convenient custom variables .
in addition ,environment Instructions can be in pipeline In the definition of , Represents that the variable scope is the entire pipeline; It can also be in stage In the definition of , Representative variables are only valid at this stage .
If in environment The variables defined in are the same as env Duplicate variable names in , Then the value of the variable with the same name will be overwritten .

1.3、 Custom global environment variables

occasionally , We need to define some global cross pipeline The custom variable for .<

版权声明
本文为[Lao wa next door]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231923218897.html