Explore Courses Blog Tutorials Interview Questions
0 votes
in Azure by (45.3k points)

I have an ARM template that has and outputs section like the following:

"outputs": {

    "sqlServerFqdn": {

        "type": "string",

        "value": "[reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName]"


    "primaryConnectionString": {

        "type": "string",

        "value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('databaseName'), ';User Id=', parameters('administratorLogin'), '@', variables('sqlserverName'), ';Password=', parameters('administratorLoginPassword'), ';')]"


    "envResourceGroup": {

        "type": "string",

        "value": "[parameters('hostingPlanName')]"



I have an Azure Resource Group Deployment task that uses the template. I then want to use the variable $(sqlServerFqdn) in the next task for configuration. The variable doesn't seem to just populate and I cannot find anywhere that tells me how to use 'outputs' values on release.

What do I need to do to get the variable to populate for use in configuring tasks after this ARM template runs? An example would be in the parameters to a PowerShell script task or another ARM template.

1 Answer

0 votes
by (16.8k points)

Simply add this to your PowerShell script following your ARM Template:


 [string]  $resourceGroupName


$lastDeployment = Get-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName | Sort Timestamp -Descending | Select -First 1 

if(!$lastDeployment) {

    throw "Deployment could not be found for Resource Group '$resourceGroupName'."


if(!$lastDeployment.Outputs) {

    throw "No output parameters could be found for the last deployment of Resource Group '$resourceGroupName'."


foreach ($key in $lastDeployment.Outputs.Keys){

    $type = $lastDeployment.Outputs.Item($key).Type

    $value = $lastDeployment.Outputs.Item($key).Value

    if ($type -eq "SecureString") {

        Write-Host "##vso[task.setvariable variable=$key;issecret=true]$value" 


    else {

        Write-Host "##vso[task.setvariable variable=$key;]$value" 


Note that the environmental variables won't be available in the context of this script, but will in subsequent tasks.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers


108k users

Browse Categories