microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.5k stars 2.61k forks source link

Allow ARM template deployment tasks to set ARM output variables as pipeline variables #13032

Open tonesandtones opened 4 years ago

tonesandtones commented 4 years ago

Required Information

Entering this information will route you directly to the right team and expedite traction.

Question, Bug, or Feature?
Type: Feature

Enter Task Name: AzureResourceGroupDeploymentV2 and AzureResourceManagerTemplateDeploymentV3

https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureResourceGroupDeploymentV2 https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureResourceManagerTemplateDeploymentV3

Environment

Issue Description

As a pipeline yml author, I would like a simple way to make ARM template outputs available as pipeline variables.

Azure ARM deployment tasks do not provide the ability to unwrap template outputs and set them as pipeline variables. The readme for https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureResourceManagerTemplateDeploymentV3 even offers a Powershell snippet for doing this.

$var=ConvertFrom-Json '$(storageAccountName)'
$value=$var.storageAccountName.value
Write-Host "##vso[task.setvariable variable=storageAccount;]$value"

It should not be necessary to add a separate script/pwsh/powershell step to unwrap the outputs section to make ARM outputs available as pipeline variables. Script snippets like this are easy to get wrong and difficult to get right across the various agent OSes and ARM output variable types.

I propose adding a boolean parameter to control the behaviour, such as expandDeploymentOutputAsVariables: true. When set to true, all output variables from the ARM template execution are set as pipeline variables, similar to if you included a script snippet like the above example.

Task logs

n/a - feature request

Troubleshooting

n/a - feature request

Error logs

n/a - feature request

TomBonnerAtTFL commented 4 years ago

There you go. I've raised a PR to add to the script so that the full object is outputted as individual parameters.

This means that the object:

{
    "test": {
        "type": "String",
        "value": "my_storage"
    },
    "storageAccountKey":
    {
        "type": "String",
        "value": "Hello!"
    },
    "storageAccountContainer":
    {
        "type": "String",
        "value": "backup"
    }
}

Will become:

"OutputVar.test.type" = "String"
"OutputVar.test.value" = "my_storage"
"OutputVar.storageAccountKey.type" = "String"
"OutputVar.storageAccountKey.value" = "Hello!"
"OutputVar.storageAccountContainer.type" = "String"
"OutputVar.storageAccountContainer.value" = "backup"