gpt4 book ai didi

azure - 是否可以根据条件添加运行时参数 - Azure Devops Pipeline

转载 作者:行者123 更新时间:2023-12-02 22:49:18 25 4
gpt4 key购买 nike

我当前的 azure 管道如下所示 -

parameters:
- name: Deploy
type: Boolean
default: false
- name: Stages
type: string
values:
- Stg A
- Stg B
- Stg C
- Stg D
- Stg E

我试图添加一个条件,如果用户在运行管道上检查Deploy,它应该仅动态显示Stg AStg B 作为Stages 的值。如果他们取消选中部署,它应该显示Stg CStg DStg E

我尝试通过以下方式添加条件 -

 parameters:
- name: Deploy
type: Boolean
default: false
- name: Stages
type: string
${{ if eq(parameters['Deploy'], 'true' ) }}:
values:
- Stg A
- Stg B
${{ if ne(parameters['Deploy'], 'true' ) }}:
values:
- Stg C
- Stg D
- Stg E

但是,以下条件方式适用于变量,但不适用于参数。有什么方法可以在 Azure 管道中实现此目的。

最佳答案

Is it possible to add runtime parameters based on condition - Azure Devops Pipeline

恐怕运行时参数不可能基于另一个参数值有条件地定义值。

因为在管道运行开始之前需要定义参数。如文档Runtime parameters中所述:

Parameters are only available at template parsing time. Parameters areexpanded just before the pipeline runs so that values surroundedby ${{ }} are replaced with parameter values. Use variables if youneed your values to be more widely available during your pipeline run.

作为解决方法,我们可以在步骤中使用条件:

 parameters:
- name: Deploy
type: Boolean
default: false

stages:
- ${{ if eq(parameters['Deploy'], 'true' ) }}:
- template: template.yml
parameters:
stages:
- "Stg A"
- "Stg B"
- ${{ if ne(parameters['Deploy'], 'true' ) }}:
- template: template.yml
parameters:
stages:
- "Stg C"
- "Stg D"
- "Stg E"

关于azure - 是否可以根据条件添加运行时参数 - Azure Devops Pipeline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67184922/

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