Jenkins 内置变量 和变量作用域

作者 : admin 本文共1194个字,预计阅读时间需要3分钟 发布时间: 2024-06-10 共1人阅读

参考

##  参考
http://www.cnblogs.com/weiweifeng/p/8295724.html

常用的内置变量

## 内置环境变量地址
${YOUR_JENKINS_HOST}/jenkins/env-vars.html


##  内置环境变量列表
http://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.
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.

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.
pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                envInject {
                    env:
                        [
                            STEP_VAR = "step value"
                        ]
                }
                // GLOBAL_VAR, STAGE_VAR, and STEP_VAR are available here
            }
        }
    }
}

本站无任何商业行为
个人在线分享 » Jenkins 内置变量 和变量作用域
E-->