gpt4 book ai didi

azure - 使用 System.PullRequest.TargetBranch 动态设置变量组

转载 作者:行者123 更新时间:2023-12-02 06:18:01 26 4
gpt4 key购买 nike

我正在尝试使用 azure devops 在拉取请求管道中动态设置组。 Yaml 文件如下所示:

variables:
- ${{ if eq(variables['System.PullRequest.TargetBranch'], 'refs/heads/dev') }}:
- group: dev-var-group

这不起作用,条件被评估为“假”。只是为了确认这一点,我颠倒了如下条件

variables:
- ${{ if ne(variables['System.PullRequest.TargetBranch'], 'refs/heads/dev') }}:
- group: dev-var-group

正确设置该组后,读取所有必需的变量并且管道工作。

任何人都可以在这里提供帮助,使其在正确的条件下工作吗?

最佳答案

恐怕这是不可能的。如果你看hereTemplate expression syntax :

You can use template expression syntax to expand both template parameters and variables (${{ variables.var }}). Template variables are processed at compile time, and are replaced before runtime starts. Template expressions are designed for reusing parts of YAML as templates.

Template variables silently coalesce to empty strings when a replacement value isn't found. Template expressions, unlike macro and runtime expressions, can appear as either keys (left side) or values (right side). The following is valid: ${{ variables.key }} : ${{ variables.value }}.

要使其正常工作,您需要一个模板变量和 System.PullRequest.TargetBranch是运行时变量,因此它被替换为空字符串。如果您检查预定义变量 here你会注意到最后一栏Available in templates?

enter image description here

上面写着no对于 System.PullRequest.TargetBranch

关于azure - 使用 System.PullRequest.TargetBranch 动态设置变量组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63941345/

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