Azure DevOps的YAML流水线未设置变量。

3

我有一个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
1个回答

2

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接