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
            }
        }
    }
}
相关推荐
秋秋秋秋秋雨2 小时前
linux安装单节点Elasticsearch(es),安装可视化工具kibana
linux·elasticsearch·jenkins
去伪存真6 小时前
不用动脑,手把手跟着我做,就能掌握Gitlab+Jenkins提交代码自动构部署
前端·jenkins
Hello.Reader14 小时前
在 Ubuntu 环境为 Elasticsearch 引入 `icu_tokenizer
ubuntu·elasticsearch·jenkins
秦始皇爱找茬1 天前
docker部署Jenkins工具
docker·容器·jenkins
洞窝技术1 天前
增量代码自动Review工具:洞窝在AI上的探索和实践
jenkins·ai编程·测试
风行無痕2 天前
Ubuntu使用war包部署Jenkins并通过systemcl管理
java·servlet·jenkins
rider1893 天前
【3】CICD持续集成-k8s集群中安装Jenkins-agent(主从架构)
ci/cd·kubernetes·jenkins
云攀登者-望正茂3 天前
Jenkins plugin 的用法和示例
kubernetes·jenkins
007php0073 天前
使用 Docker 安装 Elastic Stack 并重置本地密码
大数据·运维·后端·mysql·docker·eureka·jenkins
suimeng63 天前
Jenkins的地位和作用
自动化测试·jenkins