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
            }
        }
    }
}
相关推荐
Zhou1411362 天前
CICD_01_持续集成与Jenkins入门
运维·ci/cd·jenkins
大貔貅喝啤酒2 天前
Gitea+Jenkins+Docker 搭建 Node 项目 CI/CD 自动部署完整教程
ci/cd·docker·jenkins·js·gitea
guo_wen_qiang3 天前
jenkins流水线参数化配置
运维·docker·容器·jenkins·持续部署
何中应4 天前
Jenkins 如何给设置公司 Logo
运维·ci/cd·jenkins
何中应4 天前
Jenkins 如何配置工作节点
运维·ci/cd·jenkins
wjjzhbb5 天前
Jenkins到ArgoCD——GitOps持续交付实践
运维·缓存·jenkins·argocd
小鱼,5 天前
Jenkins构建完成后发送飞书通知消息
jenkins·cicd
不吃香菜kkk、11 天前
CI/CD(GitOps)学习与部署手册
运维·云原生·容器·kubernetes·云计算·jenkins·argocd
qq_3494479516 天前
Ubuntu26安装jenkins
jenkins
蓝天星空16 天前
Jenkins项目矩阵授权配置
jenkins