【问题标题】:if condition with "or" & "änd" in yaml azure devops如果在 yaml azure devops 中带有“或”和“änd”的条件
【发布时间】:2021-09-08 01:18:38
【问题描述】:

如果满足以下条件,我想写:

  1. 运行 ax 分析应设置为 true
  2. 构建原因应该是拉取请求
  3. 源分支应该是开发分支(当用户选择任何其他分支时[ex:release] ax 不应该运行)
  4. 自定义标签值不应为空

我尝试了以下条件

- ${{ if or(eq(parameters.axe_flag, true) , eq(variables['Build.Reason'], 'PullRequest')) }}: 

- ${{ if and(not(eq(parameters.cust_tagName, 'null' )) ,startsWith(variables['Build.SourceBranch'], 'refs/heads/develop')) }}:

condition: and(succeeded(), or(startsWith(variables['Build.SourceBranch'], 'refs/heads/develop'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'), startsWith(variables['Build.SourceBranch'], 'refs/heads/develop-map')))

如果条件不起作用,则为多个。继续低于错误

Exactly 1 parameter(s) were expected following the directive 'if'. Actual parameter count: 2
/templates/build.yml@templates (Line: 40, Col: 3): Unexpected value '${{ if or(eq(parameters.sonarqube_flag, true) , eq(variables['Build.Reason'], 'PullRequest')), and(not(eq(parameters.cust_tagName, 'null' )) ,startsWith(variables['Build.SourceBranch'], 'refs/heads/develop')) }}'
/templates/build.yml@templates: (Line: 46, Col: 14, Idx: 1828) - (Line: 46, Col: 14, Idx: 1828): Mapping values are not allowed in this context.

当我添加带有 and 条件的第二个 if 语句时,第一个带有 or 条件的 if 语句可以完美运行而没有错误,继续收到以下错误。关于如何处理多种情况的任何建议都会非常有帮助。提前致谢。

【问题讨论】:

  • 你能告诉你完整的管道吗?
  • 不幸的是,我无法分享完整的管道。您能否就如何处理多个 if 条件提出建议。 @KrzysztofMadej

标签: azure-devops azure-pipelines-yaml


【解决方案1】:

您似乎正在添加允许标量值的模板条件(if 语句) - 请注意 if 语句开头的减号 - 这使其成为非标量。还要检查错误“在此上下文中不允许映射值”

这是一般 YAML 模板中的常见错误 - 请参阅此处

YAML mapping values are not allowed in this context

如果共享了完整的 YAML,那可能会更好,因为我只是根据错误消息提供解决方案

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-13
    • 1970-01-01
    • 2020-08-26
    • 2020-09-15
    • 2023-02-11
    • 2021-12-31
    • 1970-01-01
    • 2021-09-04
    相关资源
    最近更新 更多