gpt4 book ai didi

azure - 根据 Azure DevOps Pipelines YAML 中的条件隐藏/显示参数

转载 作者:行者123 更新时间:2023-12-03 05:21:12 26 4
gpt4 key购买 nike

我有一个用例,其中 ADO 构建管道中有多个参数,但这些参数应该根据条件可见,例如分支名称(对于releases/*分支)。以下是展示我想要实现的目标的模板:

variables:
- name: systemAccessToken
value: $(System.AccessToken)
- name: system.debug
value: true
- ${{if startsWith(variables['Build.SourceBranch'], 'refs/heads/releases/') }}:
- name: START_DATE_TIME
value: ${{ parameters.startDateTime }}
- name: END_DATE_TIME
value: ${{ parameters.endDateTime }}

- ${{if startsWith(variables['Build.SourceBranch'], 'refs/heads/releases/') }}:
parameters:
- name: startDateTime
displayName: Enter the Start Datetime
type: string
default: 04-14-2022 14:55:00
- name: endDateTime
displayName: Enter the End Datetime
type: string
default: 04-14-2022 23:00:00

resources:
repositories:
...
...


stages:
...
...

上面的方法不起作用,但我想知道是否有某种方法可以使用任何解决方法(例如在运行时注入(inject)参数)来实现此目的。对此有任何帮助将不胜感激

最佳答案

抱歉,无法完成。在了解任何运行时变量(例如 Build.SourceBranch)之前,参数列表已固定,管道已编译。

相反,您也许可以使用不同的参数集定义两个不同的管道?您可以通过将公共(public)元素(资源、变量、阶段)提取到模板中来避免重复代码。

关于azure - 根据 Azure DevOps Pipelines YAML 中的条件隐藏/显示参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72185081/

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