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
还有这个:
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 template is not allowed. azure-pipelines.yml 8
上述语法有什么问题,需要什么才能达到要求而不出错?
答案 0 :(得分:1)
错误属性 ${{ if eq('true', 'true') }} 是不允许的。 azure-pipelines.yml 8
根据错误消息,Visual Studio 中存在此问题。
这是关于 If expression in Azure Devops 的文档。
您可以直接在 Azure Pipeline 中创建 yaml 示例。
它可以在 Azure Devops Pipeline 中正常工作。
对于格式condition: eq('true', 'true')
,模板字段不支持添加条件参数,所以不能使用。
更新:
与 Mark 讨论,“if”语法在 Yaml 文件中确实有效,但由于新版本 Visual Studio 中的限制,它在 Visual Studio 中显示为错误。