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
            }
        }
    }
}
相关推荐
凤凰战士芭比Q7 小时前
Jenkins(部署、基础项目)
运维·servlet·jenkins
沈健_算法小生7 小时前
Jenkins权限控制实现
运维·jenkins
health_2010@163.com1 天前
jenkis下载,部署,打包
jenkins
weixin_307779131 天前
赋能插件,驱动图表:Jenkins ECharts API插件详解
运维·开发语言·自动化·jenkins·echarts
一周困⁸天.1 天前
Jenkins 自动化部署 PHP 项目
自动化·jenkins·php
杀手不太冷!1 天前
Jenkins的安装与使用;git clone url的时候,url为http和ssh时候的区别
git·http·jenkins
flying robot1 天前
ELK单节点集群配置
运维·elk·jenkins
沈健_算法小生1 天前
Ubutun22.04离线部署Jenkins最新版
运维·jenkins
野生技术架构师1 天前
SpringBoot+Elasticsearch实现高效全文搜索
spring boot·elasticsearch·jenkins
weixin_307779131 天前
Jenkins Pipeline: Input Step插件详解与实践指南
运维·开发语言·自动化·jenkins·etl