繁体   English   中英

azure devops yaml 管道未设置变量

[英]azure devops yaml pipeline not setting the variables

我有一个 yaml 管道,它运行以下模板/变量:

    variables:
    - template: vars/global.yaml
    steps:
    - template: steps/debug-vars.yaml

这是 global.yaml:

variables:
  isMain:              ${{ eq(variables['Build.SourceBranch'], 'refs/heads/main') }}
  isProduction:        ${{ eq(variables['Build.SourceBranch'], 'refs/heads/production') }}
  isTag:               ${{ startsWith(variables['Build.SourceBranch'], 'refs/tags/v') }}
  isFork:              ${{ eq(variables['System.PullRequest.IsFork'], 'True') }}
  isPR:                ${{ eq(variables['Build.Reason'], 'PullRequest') }}
  isTrustedCode:       ${{ eq(variables.isFork, 'False') }}
  isScheduled:         ${{ eq(variables['Build.Reason'], 'Schedule') }}
  isTrustedCI:         ${{ and( eq(variables.isFork,'False'), eq(variables.isPR,'False'), eq(variables.isScheduled,'False') ) }}

debug-vars.yaml 使用以下代码检查 vars/global.yaml 中的值:

steps:
- bash: |
    echo ""
    echo "---------"
    echo "Debugging"
    echo "---------"
    echo  "isMain: ${{ variables.isMain }}"
    echo  "isProduction: ${{ variables.isProduction }}"
    echo  "Build.SourceBranch: ${{ variables['Build.SourceBranch'] }}"
  displayName: Debug - Branch Variables

但是当我从主分支运行 CD 管道时,Build.SourceBranch 被填充而“isMain”不是,知道为什么吗?

---------
Debugging
---------
isMain: 
isProduction: 
Build.SourceBranch: refs/heads/main
Finishing: Debug - Branch Variables

修复是将 debug-vars.yaml 中的语法从: ${{ variables.isMain }}更改为$(isMain)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM