Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tonesandtones opened this issue May 29, 2020 · 1 comment
Assignees
Labels
Area: Release backlog Work that is on the backlog and won't get marked stale enhancement

Comments

@tonesandtones
Copy link

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

  • Server - Azure Pipelines

  • Agent - Hosted

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

@bishal-pdMSFT bishal-pdMSFT added the backlog Work that is on the backlog and won't get marked stale label Aug 2, 2020
TomBonnerAtTFL added a commit to TomBonnerAtTFL/azure-pipelines-tasks that referenced this issue Oct 30, 2020
Added code that expands the returned Outputs object into Pipeline variables so they can be used easily in scripts. This fixes issue microsoft#13032.
@TomBonnerAtTFL
Copy link
Contributor

TomBonnerAtTFL commented Oct 30, 2020

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"

TomBonnerAtTFL added a commit to TomBonnerAtTFL/azure-pipelines-tasks that referenced this issue Nov 18, 2020
bishal-pdMSFT pushed a commit that referenced this issue Nov 23, 2020
* Expand ARM output into Pipeline variables

Added code that expands the returned Outputs object into Pipeline variables so they can be used easily in scripts. This fixes issue #13032.

* Updated Minor version

* Updated Minor version

* Updated minor version number

* Updated minor version number

* Expand variables into separate environment vars

Expands the fix for issue #13032.

* Updated patch

* Updated patch

* Added console.log when setting variable

* Added console.log when setting variable

* Swapped to use spaces to be consistent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Release backlog Work that is on the backlog and won't get marked stale enhancement
Projects
None yet
Development

No branches or pull requests

4 participants