gpt4 book ai didi

azure devops yaml管道未设置变量

转载 作者:行者123 更新时间:2023-12-05 04:44:12 29 4
gpt4 key购买 nike

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

关于azure devops yaml管道未设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69419861/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com