【发布时间】:2021-11-23 22:14:59
【问题描述】:
我有一个运行以下模板/变量的 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
【问题讨论】:
标签: azure azure-devops yaml