为什么我不能在Azure DevOps的YAML模板中将运行时变量传递到if条件中?

3

我认为我在PowerShell步骤中错误地调用了我的变量os_name;每次测试构建时,它都无法通过我的if语句。我想知道我的代码有什么问题。是否有人尝试过在Azure DevOps表达式中使用运行时变量类似于这样的方法?

      - powershell: |
          $os_name = 'linux'
          echo "##vso[task.setvariable variable=os_name;]$os_name"

      - ${{ if eq( variables.os_name , 'linux') }}:
        - powershell: |
            echo "variables.os_name = linux"
1个回答

2
这应该适用于您:
- task: PowerShell@2
  displayName: set variable
  inputs:
    targetType: 'inline'
    script: |
      "##vso[task.setvariable variable=os_name;]linux"

- task: PowerShell@2
  displayName: Linux case
  inputs:
    targetType: 'inline'
    script: |
        Write-Host "Linux"
  condition: eq(variables.os_name, 'linux')

在Linux上运行:

输入图像描述

在非Linux系统上运行:

输入图像描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接