1

We use VSTS to deploy an ARM template. (Azure Deployment task version: 2). In this task, we can configure the output variable. The will output the json output of the ARM template in this variable. In my case, it is called armOutputJson.

In the next task, I have an inline powershell script that tries to convert this value to a powershell object.

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

The output seems to written to the host like this:

@{storageAccountName=; functionAppName=}

It looks like the settings are not correctly parsed? Also when trying to access this variable in my deploy task using $(armOutput).functionAppName.value, I got the following error:

[error]Error: Resource '@{storageAccountName=; functionAppName=}.functionAppName.value' doesn't exist. Resource should exist before deployment.

Anyone knows how I can parse the output json to a vsts variable and use it in another task?

Community
  • 1
  • 1
Identity
  • 1,553
  • 1
  • 22
  • 44

2 Answers2

0

Try to call Format-Custom to format the output $outputObject | Format-Custom -Depth 5

Related issue ConvertFrom-Json not deep?

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
0

You did it almost right, the approach is good, just some syntax typos. This should work (at least it works for me):

# 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"
Lukas K
  • 6,037
  • 4
  • 23
  • 31