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
            }
        }
    }
}
相关推荐
测试那点事儿7 小时前
零基础接口自动化到 Jenkins 持续集成(导读)
ci/cd·自动化·jenkins
运维全栈笔记2 天前
零基础掌握Jenkins CI/CD:Java项目自动构建与部署全流程指南
git·servlet·ci/cd·gitee·自动化·jenkins·devops
Young soul22 天前
docker-compose安装elasticsearch、kibana、logstash以及ik分词器
elasticsearch·docker·jenkins
Young soul22 天前
Elasticsearch(v8.5) 常用操作大全
大数据·elasticsearch·jenkins
何中应3 天前
记录一次Jenkins构建任务的坑
java·servlet·jenkins
kaico20184 天前
Jenkins Master 停机与备份
运维·servlet·jenkins
陈皮糖..5 天前
27 届运维实习笔记|第三、四周:从流程熟练到故障排查,企业运维实战深化
运维·笔记·sql·nginx·ci/cd·云计算·jenkins
老友@5 天前
Jenkins 中 Node 版本异常排查:Alpine + musl 导致的兼容问题(lts-alpine-jdk17)
java·servlet·jenkins
弹简特5 天前
【精通JMeter接口测试】03-JMeter 接口测试持续集成踩坑记:jtl 转 Allure 报告、Jenkins 定时执行、CSP 样式劫持全解决
jmeter·自动化·jenkins