Jenkins 内置变量 和变量作用域

参考

##  参考
https://www.cnblogs.com/weiweifeng/p/8295724.html

常用的内置变量

## 内置环境变量地址
${YOUR_JENKINS_HOST}/jenkins/env-vars.html


##  内置环境变量列表
https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables

变量作用域

Global environment

The environment block in a Jenkins pipeline can be defined at different levels, and the scope of the environment variables defined in each level varies:

  1. Global environment: Environment variables defined at the top-level environment block will be available to all stages and steps in the pipeline.
pipeline {
    agent any
    environment {
        GLOBAL_VAR = "global value"
    }
    // ...
}

Stage environment

tage environment: Environment variables defined within a specific stage block will only be available to that stage and its steps.

pipeline {
    agent any
    stages {
        stage('Stage 1') {
            environment {
                STAGE_VAR = "stage 1 value"
            }
            steps {
                // GLOBAL_VAR and STAGE_VAR are available here
            }
        }
        stage('Stage 2') {
            environment {
                STAGE_VAR = "stage 2 value"
            }
            steps {
                // GLOBAL_VAR and STAGE_VAR (stage 2 value) are available here
            }
        }
    }
}

Step environment

  1. Step environment: Environment variables can also be defined within a specific step using the envInject step, which will only be available for that step.
pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                envInject {
                    env:
                        [
                            STEP_VAR = "step value"
                        ]
                }
                // GLOBAL_VAR, STAGE_VAR, and STEP_VAR are available here
            }
        }
    }
}

相关推荐

  1. Jenkins 变量 变量作用

    2024-06-09 15:44:03       11 阅读
  2. bash 变量作用

    2024-06-09 15:44:03       33 阅读
  3. 变量作用

    2024-06-09 15:44:03       15 阅读
  4. OpenMP:变量作用

    2024-06-09 15:44:03       14 阅读
  5. 环境变量Bash命令

    2024-06-09 15:44:03       16 阅读
  6. Python 变量:创建、类型、命名规则作用详解

    2024-06-09 15:44:03       38 阅读
  7. 【UnityShader预备知识】变量函数

    2024-06-09 15:44:03       15 阅读
  8. 块级作用变量提升

    2024-06-09 15:44:03       16 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-09 15:44:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-09 15:44:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-09 15:44:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-09 15:44:03       20 阅读

热门阅读

  1. 为什么要选择AWS?AWS的优势有哪些?

    2024-06-09 15:44:03       11 阅读
  2. SASS基础知识

    2024-06-09 15:44:03       10 阅读
  3. linux的sed

    2024-06-09 15:44:03       7 阅读
  4. No signature found in package of version 2 or newer for package

    2024-06-09 15:44:03       6 阅读
  5. 进程和线程

    2024-06-09 15:44:03       7 阅读
  6. 压力测试的前置准备

    2024-06-09 15:44:03       10 阅读
  7. 未来的视窗:苹果Vision Air猜想与期待

    2024-06-09 15:44:03       9 阅读