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
            }
        }
    }
}
相关推荐
qq_4523962319 小时前
第二篇:《Jenkins 从零搭建:安装、配置与第一个 Pipeline》
java·运维·jenkins
用户67570498850220 小时前
手摸手教你玩 Jenkins,一次搞懂 CI/CD!(第三章:发布之nodeAgent)
后端·jenkins
qq_452396231 天前
第三篇:《Jenkins Pipeline as Code:Declarative Pipeline 深度实战》
java·servlet·jenkins
用户6757049885022 天前
手摸手教你玩 Jenkins,一次搞懂 CI/CD!(第二章:发布之sshPublisher)
后端·jenkins
用户6757049885022 天前
手摸手教你玩 Jenkins,一次搞懂 CI/CD!(第一章:部署)
后端·jenkins
行者-全栈开发2 天前
Jenkins 与 GitLab 深度集成实战:从 Webhook 到 Merge Request 全流程自动化
gitlab·jenkins·webhook·merge request·multibranch·source plugin·ci/cd 自动化
2301_780303905 天前
DevSecOps建设之自动化集成与部署 Jenkins教程和使用案例
运维·自动化·jenkins
longze_711 天前
Github仓库一直拉取不了
github·jenkins
醉颜凉1 个月前
Elasticsearch高性能优化:Bulk API大规模数据导入性能调优全攻略
elasticsearch·性能优化·jenkins
sbjdhjd1 个月前
从零搭建企业级 CI/CD(下):Jenkins+GitLab+Harbor 全链路实战指南
git·servlet·ci/cd·云原生·云计算·gitlab·jenkins