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
            }
        }
    }
}
相关推荐
一点事17 小时前
windows:ELK搭建(单机)
windows·elk·jenkins
lcx_defender17 小时前
【Docker】Docker部署运行Elasticsearch
elasticsearch·docker·jenkins
海兰2 天前
win11下部署elastic9.0+常见问题及解决方法(续)
运维·jenkins
海鸥812 天前
k8s中Jenkins 配置文件「 更新不了 」
java·kubernetes·jenkins
_运维那些事儿2 天前
GitLab&Jenkins
运维·ci/cd·gitlab·jenkins·devops
一念一花一世界2 天前
Jenkins 太重?试试超轻量开源 CI/CD 工具 Arbess
运维·ci/cd·jenkins·arbess
liux35282 天前
Elasticsearch 8.13.2 单机部署与配置详细指南
大数据·elasticsearch·jenkins
切糕师学AI2 天前
Jenkins Pipeline 小解
运维·servlet·jenkins
BUTCHER53 天前
elasticsearch时间搜索
大数据·elasticsearch·jenkins
Hellc0073 天前
Jenkins 上下游 Job + Docker 镜像部署完整实战(避坑版)
java·docker·jenkins