Azure Devops YML 条件阶段模板

Mar*_*ark 5 azure-devops azure-devops-pipelines

视觉工作室 2019 16.8.5

我想使用阶段模板。有些阶段,我想根据条件而定。但是,当我在 YML 文件中尝试此操作时,它会生成错误。以下是 azure-pipelines.yml 文件中的两次尝试:

stages:
- template: 'build.yml'

- template: 'deploy.yml'

- template: 'test.yml'

- ${{ if eq('true', 'true') }}:
  - template: 'optional.yml'
Run Code Online (Sandbox Code Playgroud)

结果是:

Severity    Code    Description Project File    Line    Suppression State
Error       Property ${{ if eq('true', 'true') }} is not allowed.       azure-pipelines.yml 8   
Run Code Online (Sandbox Code Playgroud)

和这个:

stages:
- template: 'build.yml'

- template: 'deploy.yml'

- template: 'test.yml'

- template: 'optional.yml'
  condition: eq('true', 'true')
Run Code Online (Sandbox Code Playgroud)

结果是:

Severity    Code    Description Project File    Line    Suppression State
Error       Property template is not allowed.       azure-pipelines.yml 8   
Run Code Online (Sandbox Code Playgroud)

上面的语法有什么问题,需要什么才能达到没有错误的要求?

Kev*_*SFT 4

不允许错误属性 ${{ if eq('true', 'true') }} 。天蓝色管道.yml 8

根据错误消息,该问题存在于 Visual Studio 中。

这是有关Azure Devops 中的 If 表达式的文档。

您可以直接在 Azure Pipeline 中创建 yaml 示例。

在此输入图像描述

它可以在 Azure Devops Pipeline 中正常工作。

对于格式condition: eq('true', 'true'),模板字段不支持添加条件参数,因此我们无法使用它。

更新:

与 Mark 讨论,“if”语法在 Yaml 文件中确实有效,但由于新版本 Visual Studio 的限制,它在 Visual Studio 中显示为错误。