• Jenkins 内置变量 和变量作用域


    参考

    1. ## 参考
    2. https://www.cnblogs.com/weiweifeng/p/8295724.html

    常用的内置变量

    1. ## 内置环境变量地址
    2. ${YOUR_JENKINS_HOST}/jenkins/env-vars.html
    3. ## 内置环境变量列表
    4. 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.
    1. pipeline {
    2. agent any
    3. environment {
    4. GLOBAL_VAR = "global value"
    5. }
    6. // ...
    7. }

    Stage environment

    tage environment: Environment variables defined within a specific stage block will only be available to that stage and its steps.

    1. pipeline {
    2. agent any
    3. stages {
    4. stage('Stage 1') {
    5. environment {
    6. STAGE_VAR = "stage 1 value"
    7. }
    8. steps {
    9. // GLOBAL_VAR and STAGE_VAR are available here
    10. }
    11. }
    12. stage('Stage 2') {
    13. environment {
    14. STAGE_VAR = "stage 2 value"
    15. }
    16. steps {
    17. // GLOBAL_VAR and STAGE_VAR (stage 2 value) are available here
    18. }
    19. }
    20. }
    21. }

    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.
    1. pipeline {
    2. agent any
    3. stages {
    4. stage('Example') {
    5. steps {
    6. envInject {
    7. env:
    8. [
    9. STEP_VAR = "step value"
    10. ]
    11. }
    12. // GLOBAL_VAR, STAGE_VAR, and STEP_VAR are available here
    13. }
    14. }
    15. }
    16. }

  • 相关阅读:
    resilience4j 重试源码分析以及重试指标采集
    QT 线程学习
    flink HelloWorld 之词频统计
    线性代数|机器学习-P23梯度下降
    2022华为软挑赛题讲解(CodeCraft-2022)
    第一类和第二类增值电信业务经营许可证的区别
    C++基础知识(十一)--- 文件读写
    PAT甲级--1035 Password
    苍穹外卖-day05
    Java中的集合内容总结——Collection接口
  • 原文地址:https://blog.csdn.net/knight_zhou/article/details/139537708