Azure Devops YML Conditional Stage Template

Viewed 6070

Visual Studio 2019 16.8.5

I want to use template for stages. Some stages, I'd like to be based on conditions. However, when I try this in the YML file, it generates errors. Here are two attempts in the azure-pipelines.yml file:

stages:
- template: 'build.yml'

- template: 'deploy.yml'

- template: 'test.yml'

- ${{ if eq('true', 'true') }}:
  - template: 'optional.yml'

Results in:

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

And this:

stages:
- template: 'build.yml'

- template: 'deploy.yml'

- template: 'test.yml'

- template: 'optional.yml'
  condition: eq('true', 'true')

results in:

Severity    Code    Description Project File    Line    Suppression State
Error       Property template is not allowed.       azure-pipelines.yml 8   

What is wrong with the above syntax and what is needed to achieve the requirement without errors?

1 Answers

Error Property ${{ if eq('true', 'true') }} is not allowed. azure-pipelines.yml 8

Based on the error message, this issue exists in the Visual Studio.

Here is a doc about If expression in Azure Devops.

You could directly create the yaml samples in Azure Pipeline .

enter image description here

It could workd fine in Azure Devops Pipeline.

For the format condition: eq('true', 'true'), the template field does not support adding condition parameter, so we cannot use it.

Update:

Discuss with Mark, the "if" syntax is indeed valid in Yaml file but that it shows as an error in Visual Studio due to the limitation in New Version Visual Studio.

Related