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 小时前
导购APP容器化CI/CD流程:Jenkins在返利系统持续部署中的实践
运维·ci/cd·jenkins
黛玉晴雯子0012 小时前
Devops基础之Jenkins持续集成工具(持续更新)
ci/cd·jenkins·devops
少云清1 天前
【接口测试】3_持续集成 _Jenkins
运维·ci/cd·jenkins
weixin_390308462 天前
Jenkins报Host key verification failed错误
python·jenkins
梁萌3 天前
Jenkins流水线配置的两种方式
运维·jenkins·jenkinsfile·流水线配置
筑梦之路3 天前
Jenkins 构建部署多模块Java应用流水线参考——筑梦之路
java·运维·jenkins
K_Men4 天前
springboot 接入Elasticsearch的聚合查询
spring boot·elasticsearch·jenkins
电商API&Tina4 天前
【电商API接口】多电商平台数据API接入方案(附带实例)
运维·开发语言·数据库·chrome·爬虫·python·jenkins
梁萌4 天前
Jenkins自动化部署(docker)
docker·自动化·jenkins·流水线·cicd·smartadmin
tzhou644524 天前
搭建Jenkins+GitLab持续集成环境
ci/cd·gitlab·jenkins