1
votes

Is it possible to output a hashtable from an Azure DevOps YAML Pipeline PowerShell Task, store it to a pipeline variable and then pass the hashtable to a second PowersShell task? The receiving Script is running the 'New-AzResourceGroupDeployment' commandlet with "-TemplateParameterObject", which requires a hashtable as the argument.

I have only been able to pass strings to and from pipeline variables. I believe this proves that my syntax for outputting and receiving the variables between stages/tasks is correct. My understanding is that Azure DevOps pipeline variables store strings and there is no way for the engine to recognize a PowerShell hashtable. Is that correct?

Has anyone been able to pass a hashtable as a pipeline variable?

Here is the code which outputs the hashtable:

$TemplateSecretObject = @{
   keyVaultObject       = $KeyVaultObject
   keyVaultSecretObject = $KeyVaultSecretObject
}
Write-Host "##vso[task.setvariable variable=keyVaultSecretTaskOutput;isOutput=true]$TemplateSecretObject"
1
Hi, Is there any update for this issue? Feel free to let me know if the answer could give you some help. Just a reminder of this.Vito Liu
Hi, Just checking in to see whether this issue is still blocking you now? Any update for this issue?Vito Liu
We decided to pass JSON to a parameter, our deployment script then uses 'convertfrom-json -AsHashtable' for create the template deployment objectRNG9

1 Answers

0
votes

You should be able to serilaize hashtable to a JSON string:

'##vso[task.setvariable variable=keyVaultSecretTaskOutput;isOutput=true]{0}' -f (
  $TemplateSecretObject | ConvertTo-JSON -Depth 100 -Compress
)

And then convert it in your script back to hashtable:

$hashtable = '$(SourceTaskName.keyVaultSecretTaskOutput)' | ConvertFrom-JSON -Depth 100 -AsHashtable