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
            }
        }
    }
}
相关推荐
t***265912 分钟前
Springboot中使用Elasticsearch(部署+使用+讲解 最完整)
spring boot·elasticsearch·jenkins
g***72701 小时前
(CICD)自动化构建打包、部署(Jenkins + maven+ gitlab+tomcat)
自动化·jenkins·maven
起风了___2 小时前
Jenkins + Kubernetes 多模块微服务一键流水线:从 Maven 打包到滚动发布完整脚本
kubernetes·jenkins
star_111220 小时前
Jenkins部署后端springboot微服务项目
spring boot·微服务·jenkins
wan_da_ren3 天前
Docker安装Elasticsearch9.2.1与Kibana9.2.1 保姆教程(带验证版)
运维·docker·jenkins
要站在顶端3 天前
基于 curl 实现 Jenkins 上传制品到 JFrog Artifactory
运维·ci/cd·jenkins
小安同学iter4 天前
三台服务器,一套流水线:如何实现无缝自动化部署?
gitlab·jenkins
...对方正在输入......4 天前
Elasticsearch集群部署实战指南
elasticsearch·jenkins
程序员潇潇4 天前
Jenkins 插件下载速度慢安装失败?这篇文章可能解决你头等难题!
运维·自动化测试·软件测试·功能测试·程序人生·职场和发展·jenkins
ζั͡山 ั͡有扶苏 ั͡✾5 天前
EFK 日志系统搭建完整教程
运维·jenkins·kibana·es·filebeat