powershell - 通过脚本设置管道变量时,Azure DevOps 是否删除引号?

标签 powershell azure-devops arm-template

我必须在我的 Azure DevOps 管道中为 ARM 模板设置一个数组。我这样设置我的变量:


$foo = '["' + 'bar' + '"]'
Write-Host $foo
#######Assign Variables with Correct Value in pipeline
Write-Host "##vso[task.setvariable variable=fooVariableInPipeline]$foo"


$foo 值很好,正如预期的那样 ["bar"]。
但是当我在设置变量后检查下一个任务中的值时,它会删除引号并将值显示为 [bar]。

这很奇怪,我想知道是我还是错误?任何解决方法?

目前,我已经使用powershell代码直接更新了我的文件。

最佳答案

Does Azure DevOps remove quotation marks when setting a pipeline variable via a script?



此问题并非来自 azure devops,而是取决于您下一个任务的语法。

如果我使用 command line输出该变量的任务,它工作正常:
echo $(fooVariableInPipeline)

输出:

enter image description here

然而 ,如果我们使用 powershell输出它的任务,它将删除引号:
Write-Host "fooVariableInPipeline is $(fooVariableInPipeline)"

输出:

enter image description here

要解决这个问题,我们需要用 将变量括起来。单引号使其成为 文字字符串 , 喜欢:
$Testfoo= '$(fooVariableInPipeline)'

Write-Host "Testfoo is $Testfoo"

现在,它工作正常:

enter image description here

希望这可以帮助。

关于powershell - 通过脚本设置管道变量时,Azure DevOps 是否删除引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61746209/

相关文章:

powershell - 如何在 PowerShell 中使用 cookie 执行 wget

powershell - 为 Node.js/PHP 构建 Windows Azure PowerShell CmdLet 时出现问题

.net-core - 如何忽略构建中的测试项目?

azure-web-app-service - 如何输出通过 ARM 模板部署的应用服务的 IP 地址

azure-logic-apps - Azure 逻辑应用的字符串连接问题

powershell - 有条件地管道到 Out-Null

powershell - 如何在 PowerShell 中将输出添加/组合到现有数组?

azure-devops - 子和的 DAX 表达式

azure-devops - 如何在 Azure DevOps 中读取发布管道中工件的目录路径?

azure-logic-apps - 对于使用已存在且已连接的 OAuth 的 API 连接,逻辑应用程序 ARM 部署失败