如何在azure devops yml任务中的下一个powershell任务中设置变量布尔值以查找其真或假,然后相应地设置值?

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

我的 yml 中有以下任务,但是当我尝试将 $(setOutput.myOutputJobVar) 的值存储在 powershell azure devops yml 中的某个变量中时,它不起作用,并且说术语“true”不被识别为 cmdlet、函数等等

有什么想法吗?

jobs:
- job: A
  steps:
  - powershell: |
     Write-Host "##vso[task.setvariable variable=myOutputJobVar;isoutput=true]this is the same job too"
    name: setOutput

  - powershell: |
     Write-Host $(setOutput.myOutputJobVar)

我想要一些东西

$a = $(setOutput.myOutputJobVar)
if ($a -eq 'true') { $var = "Hello" } else { "" }
azure-devops yaml azure-pipelines
1个回答
0
投票

Azure DevOps 管道中的变量始终存储为字符串,不存在布尔值的概念。

就 powershell 而言,您可以在变量引用之前添加另一个

$
将其转换为布尔值,如下所示:

$a = $$(setOutput.myOutputJobVar)
© www.soinside.com 2019 - 2024. All rights reserved.