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 a 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.
You just need to add an output variable name for "Azure Resource Group Deployment" task like following:
And then use the variable in "PowerShell on Target Machines" task:
"PowerShell on Target Machines" task will use the resource configured in "Azure Resource Group Deployment" task:
Refer to this link for more details: Azure Resource Group Deployment Task
The output value shown on the UI for the Visual Studio Team Services task for Azure Resource Group Deployment only seems to work for the scenario described in Eddie's answer, which is for VMs. In fact, if your deployment doesn't include VMs, you will get an error something like:
For non-VM examples, I created a powershell script that runs after the RG deployment. This script, as an example, takes input variables for resource group
$resourceGroupName
and the name of the output variable you need$rgDeploymentOutputParameterName
. You could customize and use something similar:Capturing this answer because I always end up at this question when searching for the solution.
There is a marketplace task which makes ARM template output parameters available further down the pipeline. But in some cases you don't have permission to purchase marketplace items for your subscription, so the following PowerShell will do the same thing. To use it you add it as a powershell script step immediately following the ARM template resource group deployment step. It will look at the last deployment and pull the output variables into pipeline variables.
Note that the environmental variables won't be available in the context of this script, but will in subsequent tasks.
VSTS allows setting variables in powershell scripts which you can use in other tasks.
The syntax is
Write-Host "##vso[task.setvariable variable=myvariable;]myvalue"
You can have an inline Powershell script which can set the required variable to consume in yet to be executed tasks.You can access it like
$(myvariable)
.You may need to
system.debug
variable totrue
to use this.Read more details here.
First you define the Azure Resource Deployment Task and in this context the
Deployment outputs
In the next step you create a PowerShell Task that takes the
Deployment outputs
defined above as input argumentsThe PowerShell script looks as follows and assigns for each output defined in the ARM template a separate VSTS environment variable with the same name as defined in the ARM template output section. These variables can then be used in subsequent tasks.
In a subsequent task you can access the environment variables either by passing them as argument via
'$(varName)'
(this works forSecureString
too) or e.g. in a PowerShell script via$env:varName
(this does not work forSecureString
)VSTS Azure Resource Group Deployment task has outputs section now (since January 2018). So you can set variable name in Deployment outputs of Azure Resource Group Deployment task to, for example,
ResourceGroupDeploymentOutputs
and add PowerShell Script task with the following inline script:And in subsequent tasks you can use your template variables. So, for example, if you have
sqlServerFqdn
variable in your template it will be available as$(RGDO_sqlServerFqdn)
after PowerShell Script task is completed.