Check deployment results

46 Views Asked by At

I'm deploying a bicep template in a powershell script (in Devops Pipeline) using az deployment group create The problem is that if the deployment fails, my powershell script just continues instead of immediately failing. Tried to get the result via this way : $deployment_result = az deployment group create But the variable remains empty.

Any solution to get a result back so we can check and if necessary throw an exception ourselves?

Regards, Sven Peeters

1

There are 1 best solutions below

0
Jahnavi On BEST ANSWER

To check the deployment results or to handle any conflicts during deployment, use below approaches given with ifloop using Comparison operators: -match& -eq.

Approach-1:

$deploy = az deployment group create --name newdeploy --resource-group Jahnavi --template-file latest.bicep
$json = $deploy | convertfrom-json                     
 if($json.properties.provisioningState -eq "Succeeded"){
    write-host "Deployment success"
 }
 else{
   write-host "failed"
 }

enter image description here

Approach-2:

$deploy = az deployment group create --name newdeploy --resource-group Jahnavi --template-file latest.bicep
if($deploy -match '"provisioningState": "Succeeded"'){   
    write-host "deployment success"
 }
else {
    write-host "failed"
 }

enter image description here