Jenkins 内置变量 和变量作用域

参考

bash 复制代码
##  参考
https://www.cnblogs.com/weiweifeng/p/8295724.html

常用的内置变量

bash 复制代码
## 内置环境变量地址
${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.
Groovy 复制代码
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.

Groovy 复制代码
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.
Groovy 复制代码
pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                envInject {
                    env:
                        [
                            STEP_VAR = "step value"
                        ]
                }
                // GLOBAL_VAR, STAGE_VAR, and STEP_VAR are available here
            }
        }
    }
}
相关推荐
i_am_a_div_日积月累_13 小时前
jenkins打包报错
运维·rust·jenkins·jenkins打包报错
一个处女座的暖男程序猿13 小时前
2G2核服务器安装ES
服务器·elasticsearch·jenkins
一个处女座的暖男程序猿1 天前
2G2核服务器安装ES 7X版本
服务器·elasticsearch·jenkins
GeminiJM1 天前
优化Elasticsearch批量写入性能:从单分片瓶颈到多索引架构
elasticsearch·架构·jenkins
matrixlzp1 天前
Jenkins 实战2:pipeline 编写一个自动化部署
运维·jenkins
城南花开时1 天前
CCID工具,Jenkins、GitLab CICD、Arbess一文全方位对比分析
jenkins·gitlab cicd
江湖人称小鱼哥1 天前
Jenkins 在构建 Java 项目并操作 Docker 时 CPU 会突然飙高
java·docker·jenkins
snow@li1 天前
运维:部署Jenkins
运维·jenkins
zjshuster2 天前
elastic search 学习
学习·elasticsearch·jenkins
安冬的码畜日常3 天前
【JUnit实战3_22】 第十三章:用 JUnit 5 做持续集成(下):Jenkins + JUnit 5 + Git 持续集成本地实战演练完整复盘
git·测试工具·ci/cd·jenkins·集成测试·持续集成·junit5