• 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. }

  • 相关阅读:
    Linux2-系统自有服务防火墙与计划任务
    java常用部署脚本
    C2基础设施威胁情报对抗策略
    这Bug只能通过压测发现
    springboot2.5.6升级springcloud alibaba nacos
    idea提交代码冲突后,代码意外消失解决办法
    【JAVA进阶】多线程
    将秒数转换为**小时**分钟
    EasyExcel 简单导入/导出 Controller Demo
    Python安装pycrypto出错处理方法
  • 原文地址:https://blog.csdn.net/knight_zhou/article/details/139537708