Reputation: 2892
I invoke PowerShell's New-AzureRmResourceGroupDeployment
cmdlet to spin up a plethora of Azure resources according to my JSON Template.
But, often either the MongoDB or Redis VM fail to provision the first time, and I run the command again, and the provision succeeds.
Where can I programmatically know whether my deployment succeeded for all resources, and use this Boolean in a while loop to keep deploying until all resources have provisioned successfully? The cmdlet above does return an object but I haven't been able to find an indicator of success of provisioning.
Something along the lines of:
While ($didNotSucceed) {
New-AzureRmResourceGroupDeployment -TemplateFile <FileName> -ResourceGroupName <ResourceGroupName>
}
Upvotes: 0
Views: 145
Reputation: 72191
$result = New-AzureRmResourceGroupDeployment bla-bla-bla
if ($result.ProvisioningState -eq "Failed") {
New-AzureRmResourceGroupDeployment bla-bla-bla
}
Resource group deployment have ProvisioningState
property which has the provisioning state of the deployment (surprisingly). It is Failed
or Succeeded
(I haven't seen other statuses).
Also, here's what I've been using with my Jenkins build job:
try { $deploy = New-AzureRmResourceGroupDeployment @parameters }
catch { Remove-AzureRmResourceGroup -ResourceGroupName $rgName -Force; $error; $_; exit 1 }
Upvotes: 2