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