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
            }
        }
    }
}
相关推荐
安冬的码畜日常6 小时前
【JUnit实战3_22】 第十三章:用 JUnit 5 做持续集成(下):Jenkins + JUnit 5 + Git 持续集成本地实战演练完整复盘
git·测试工具·ci/cd·jenkins·集成测试·持续集成·junit5
一念一花一世界9 小时前
Jenkins vs GitLab CI/CD vs Arbess,CI/CD工具一文纵评
ci/cd·gitlab·jenkins·arbess
安冬的码畜日常11 小时前
【JUnit实战3_21】第十二章:JUnit 5 与主流 IDE 的集成 + 第十三章:用 JUnit 5 做持续集成(上):在本地安装 Jenkins
junit·eclipse·jenkins·intellij idea·持续集成·junit5·netbeans
matrixlzp12 小时前
Jenkins 实战4:集群配置与分布式构建
运维·jenkins
matrixlzp18 小时前
Jenkins 实战3:Jenkins + habor + docker 自动化部署
运维·jenkins
一念一花一世界1 天前
Jenkins vs Tekton vs Arbess,CI/CD工具一文纵评
jenkins·tekton·arbess·cicd工具
喜欢你,还有大家1 天前
集群——GitLab&&Jenkins部署
运维·gitlab·jenkins
水冗水孚2 天前
50多张图详细记录——使用Jenkins完成前端项目CICD自动化部署教程(不踩坑!)
前端·docker·jenkins
Java爱好狂.2 天前
接上篇:如何在项目中实现ES查询功能?
java·运维·jenkins·es·java面试·后端开发·java程序员
苦逼IT运维2 天前
Kubernetes 双层 Nginx 容器环境下的 CORS 问题及解决方案(极端情况)
运维·nginx·容器·kubernetes·jenkins·运维开发·ci