azure devops yaml 管道未设置变量

azure devops yaml pipeline not setting the variables

我有一个 yaml 管道 运行 以下 templates/variables:

    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)