4

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?

Mark
  • 480
  • 1
  • 5
  • 18

1 Answers1

2

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.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • Hi @Mark. From your description, it seems that you are creating the yaml file in Visual Studio, right ? The If expression exists in Azure Pipeline. I suggest that you could try to create the azure-pipelines.yml on Azure Pipeline – Kevin Lu-MSFT Mar 26 '21 at 08:59
  • Hi Kevin, thanks. So "if" is valid but "condition" is not. 1. Are you saying that my "if" syntax is valid but VS cannot handle it? If so, are other syntaxes valid but can't be handed by VS? 2. Is it just a VS bug that will be fixed? 3. "It could workd [sic] fine in Azure Devops Pipeline." Should I never use VS to edit YML files but instead always drop out to the web GUI to edit them? 4. Re the link: where on the page should I be looking to find the answer to my question, please? Thanks – Mark Mar 26 '21 at 09:17
  • 1
    1. Yes. the if expression is valid. But the VS couldn't read it. 2. As far as I know ,this is a feature exists in Azure Devops.3. Yes.Since you are using the Yaml file to create Azure Pipeline, I suggest that you could create the yaml file on web GUI instead of Visual Studio. And in Web GUI , you could validate the yaml file at one via validation option. You could try these sample in Azure Devops and check if it could work. – Kevin Lu-MSFT Mar 26 '21 at 09:23
  • This doc shows that the if expression could be used in Azure Devops Pipeline:https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops But I couldn't find that the if expression could be used in other place like visual studio – Kevin Lu-MSFT Mar 26 '21 at 09:25
  • HI Kevin. Thank you. I am surprised VS can't handle the syntax, because I thought that the whole point of adding the pipeline to a repo was that it could be edited in VS? Also, I found out this: if I rename the file to anything except azure-pipelines.yml, it no longer generates the error about the "if" expression. Given that there is no requirement to call the file "azure-pipelines.yml" (that I am aware of), I think I will do that to stop VS complaining. Finally, I tried an older version of VS and it did not complain, so I think it is a new bug in VS. – Mark Mar 26 '21 at 13:52
  • Hi @Mark. Thanks for your info. It seems that this is a limitation in visual studio 2019. I suggest that you could submit a ticket in the following site about visual studio:https://learn.microsoft.com/en-us/answers/topics/vs-general.html . – Kevin Lu-MSFT Mar 29 '21 at 05:20
  • Besides the problem with Visual Studio, did you make it work? In Azure DevOps the stage is never executed regardless of the value of the condition. – kap Feb 04 '22 at 08:20