YAML 的问题 If, elseif 条件

问题描述 投票:0回答:0

我正在尝试在我们的 Azure Devops 管道之一中使用一些条件语句,如果语句设置为 true,我正在努力让条件通过。我正在尝试这样做,以便我们可以指定如果其中一台计算机不工作,我们希望使用哪台计算机来执行任务,但如果它们都很好,则可以从池中随机选择一台。知道为什么这些条件没有被击中吗?

我已经尝试了不等于而不是等于的逆逻辑,这似乎触发了条件,但反之则不然。我已经检查以确保根据我设置的变量将变量设置为 true 或 false,并且它似乎适用于其他任务。任何帮助将不胜感激

这是设置的变量

variables:
    - name: foo1
      # Here the azure variable 'variable1' would be set to 'true' and 'variable2 would be set to 'false'
      value: $(variable1)
    - name: foo2
      value: $(variable2)

这里是构建得到需求的地方

- job: build
    displayName: build
    timeoutInMinutes: 180
    pool:
      name: 'pool'
      ${{ if eq(variables.foo1, 'true') }}:
        demands:
          - Agent.ComputerName -equals computer1
      ${{ elseif eq(variables.foo2, 'true') }}:
        demands:
          - Agent.ComputerName -equals computer2
      ${{ else }}:
        demands:
          - otherdemands
azure azure-devops yaml azure-pipelines azure-pipelines-yaml
© www.soinside.com 2019 - 2024. All rights reserved.