【问题标题】:Unable to parse ARM Output VSTS task无法解析 ARM 输出 VSTS 任务
【发布时间】:2018-06-30 08:09:04
【问题描述】:

我们使用 VSTS 来部署 ARM 模板。 (Azure 部署任务版本:2)。 在这个任务中,我们可以配置输出变量。将在此变量中输出 ARM 模板的 json 输出。在我的例子中,它被称为 armOutputJson。

在下一个任务中,我有一个内联 powershell 脚本,它尝试将此值转换为 powershell 对象。

$outputObject = ConvertFrom-Json -InputObject @"
$(armOutputJson)
"@
Write-Host "##vso[task.setvariable variable=armOutput]"$outputObject
Write-Host $outputObject

输出似乎是这样写入主机的:

@{storageAccountName=; functionAppName=}

看起来设置没有正确解析? 此外,当尝试使用 $(armOutput).functionAppName.value 在我的部署任务中访问此变量时,我收到以下错误:

[错误]错误:资源'@{storageAccountName=; functionAppName=}.functionAppName.value' 不存在。资源在部署之前应该存在。

任何人都知道如何将输出 json 解析为 vsts 变量并将其用于其他任务?

【问题讨论】:

标签: azure-resource-manager azure-pipelines-release-pipeline


【解决方案1】:

尝试调用Format-Custom格式化输出$outputObject | Format-Custom -Depth 5

Related issue ConvertFrom-Json not deep?

【讨论】:

    【解决方案2】:

    您几乎做对了,方法很好,只是一些语法错误。这应该有效(至少它适用于我):

    # parse string to json
    $outputObject = $(armOutputJson) | ConvertFrom-Json
    
    # outputObject is now object with more levels, 
    # printing it just like that does not help as each property contains nested objects
    
    # save temporary variable
    $storageAccountName = $outputObject.storageAccountName.value
    
    # export VSTS variable
    Write-Host "Setting Variable storageAccountName=$storageAccountName"
    Write-Host "##vso[task.setvariable variable=storageAccountName]$storageAccountName"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 2020-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多