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

use*_*350 17 yaml azure azure-devops azure-pipelines

我当前的天蓝色管道如下所示 -

parameters:
  - name: Deploy
    type: Boolean
    default: false
  - name: Stages
    type: string
    values:
       - Stg A
       - Stg B
       - Stg C
       - Stg D
       - Stg E
Run Code Online (Sandbox Code Playgroud)

我试图以这样的方式添加一个条件:如果用户检查正在运行的管道,它应该仅动态Deploy显示Stg A为. 如果他们取消选中,它应该显示,和。Stg BStagesDeployStg 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
Run Code Online (Sandbox Code Playgroud)

但是,以下条件方式适用于variables,但不适用于parameters。有没有办法在Azure管道中实现这一点。

Leo*_*SFT 14

\n

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

\n
\n

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

\n

因为参数需要在管道运行开始之前定义。如文档运行时参数\xef\xbc\x9a中所述

\n
\n

参数仅在模板解析时可用。参数在管道运行之前展开,以便 ${{ }} 包围的值被参数值替换。如果您需要在管道运行期间更广泛地使用您的值,请使用变量。

\n
\n

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

\n
 parameters:\n  - name: Deploy\n    type: Boolean\n    default: false\n\nstages:\n  - ${{ if eq(parameters[\'Deploy\'], \'true\' ) }}:\n    - template: template.yml\n      parameters:\n        stages:\n          - "Stg A"\n          - "Stg B"\n  - ${{ if ne(parameters[\'Deploy\'], \'true\' ) }}:\n    - template: template.yml \n      parameters:\n        stages:\n          - "Stg C"\n          - "Stg D"\n          - "Stg E"\n
Run Code Online (Sandbox Code Playgroud)\n