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
            }
        }
    }
}
相关推荐
JavaOpsPro12 小时前
jenkins部署手册
运维·jenkins·离线部署
搬砖天才、12 小时前
自动化部署-02-jenkins部署微服务
微服务·自动化·jenkins
尘佑不尘16 小时前
shodan5,参数使用,批量查找Mongodb未授权登录,jenkins批量挖掘
数据库·笔记·mongodb·web安全·jenkins·1024程序员节
独行soc19 小时前
#渗透测试#SRC漏洞挖掘# 信息收集-Shodan进阶之Jenkins组件
安全·jenkins·安全威胁分析·1024程序员节·shodan
星河顾盼1 天前
Jenkins发版出现import “html2canvas“ from “***”
运维·jenkins
金同学_jin1 天前
【测试平台】打包 jenkins配置和jenkinsfile文件
测试工具·jenkins
测试19981 天前
Python自动化测试+邮件推送+企业微信推送+Jenkins
自动化测试·软件测试·python·测试工具·职场和发展·jenkins·测试用例
不惑_1 天前
CentOS下安装ElasticSearch7.9.2(无坑版)
运维·centos·jenkins
longze_71 天前
Docker部署jenkins容器时,允许jenkins容器内部控制宿主机上的docker
docker·jenkins
TracyCoder1231 天前
掌握ElasticSearch(五):查询和过滤器
大数据·elasticsearch·jenkins