Azure devops Azure Devops YML条件阶段模板

Azure devops Azure Devops YML条件阶段模板,azure-devops,azure-devops-pipelines,Azure Devops,Azure Devops Pipelines,Visual Studio 2019 16.8.5 我想使用阶段模板。在某些阶段,我希望以条件为基础。但是,当我在YML文件中尝试此操作时,它会生成错误。以下是azure-pipelines.yml文件中的两次尝试: stages: - template: 'build.yml' - template: 'deploy.yml' - template: 'test.yml' - ${{ if eq('true', 'true') }}: - template: 'optional.ym

Visual Studio 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'
结果:

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

stages:
- template: 'build.yml'

- template: 'deploy.yml'

- template: 'test.yml'

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

Severity    Code    Description Project File    Line    Suppression State
Error       Property ${{ if eq('true', 'true') }} is not allowed.       azure-pipelines.yml 8   
Severity    Code    Description Project File    Line    Suppression State
Error       Property template is not allowed.       azure-pipelines.yml 8   
上面的语法有什么错误,需要什么来实现没有错误的需求

错误属性${如果eq('true','true')}不允许。azure-pipelines.yml 8

根据错误消息,Visual Studio中存在此问题

这是一份关于你的文件

您可以直接在Azure管道中创建yaml示例

它可以在Azure Devops管道中正常工作

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

更新:


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

Hi@Mark。根据您的描述,您似乎正在VisualStudio中创建yaml文件,对吗?Azure管道中存在If表达式。我建议您可以尝试在azure PipelineHi Kevin上创建azure-pipelines.yml,谢谢。所以“如果”有效,但“条件”无效。1.你是说我的“如果”语法是有效的,但是VS不能处理它吗?如果是的话,其他语法是否有效,但不能由VS传递?2.这只是一个VS错误,将被修复吗?3.“它可以在Azure Devops管道中正常工作。”我应该永远不要使用VS来编辑YML文件,而是总是退出到web GUI来编辑它们吗?4.回复链接:请问我应该在页面的什么地方找到我问题的答案?谢谢。对if表达式有效。但是VS看不懂。2.据我所知,这是Azure Devops.3中存在的一项功能。是的。由于您正在使用Yaml文件创建Azure管道,我建议您可以在web GUI上而不是在Visual Studio上创建Yaml文件。在Web GUI中,您可以通过验证选项一次性验证yaml文件。您可以在Azure Devops中尝试这些示例,并检查它是否可以工作。此文档显示if表达式可以在Azure Devops管道中使用:但我找不到if表达式可以在其他地方使用,如visual Studio Hi Kevin。非常感谢。我很惊讶VS不能处理语法,因为我认为将管道添加到回购协议的全部意义在于它可以在VS中编辑?此外,我发现:如果我将文件重命名为azure-pipelines.yml以外的任何文件,它将不再生成关于“if”表达式的错误。考虑到不需要调用文件“azurepipelines.yml”(我知道),我想我会这样做来停止VS抱怨。最后,我尝试了一个旧版本的VS,它没有抱怨,所以我认为这是VS中的一个新错误。