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
            }
        }
    }
}
相关推荐
闲人编程10 小时前
Elasticsearch搜索引擎集成指南
python·elasticsearch·搜索引擎·jenkins·索引·副本·分片
人间打气筒(Ada)2 天前
jenkins基于Pipeline发布项目
java·pipeline·jenkins·流水线·ci·cd·cicd
狂野小青年3 天前
Jenkins如何添加全局凭证
运维·jenkins
only_Klein3 天前
jenkins流水线报错:Connection reset by peer
ci/cd·kubernetes·gitlab·jenkins·ssl
野猪佩挤4 天前
Jenkins动态Salve调度其他集群Docker in Docker
运维·docker·jenkins
软件派4 天前
Elasticsearch终极教程:从基础到进阶的技术指南
运维·jenkins
tianyuanwo4 天前
Jenkins节点编码环境深度解析:从配置到Java Web连接原理
java·jenkins·语言编码
小韩加油呀4 天前
jenkins声明式pipline和shell从环境变量配置到打包构建再到发布到k8s
运维·kubernetes·jenkins
看世界的小gui4 天前
Jenkins通过CAS接入Maxkey单点登陆
运维·jenkins
倔强菜鸟4 天前
2026.2.2--Jenkins的基本使用
java·运维·jenkins