<p>I am using Azure devops to deploy services to AKS. There are few instances that even though the pods weren't started(in crashed state) the pipeline still shows it as success. I want to make the task/pipeline to fail if the deployment aren't successfully rolled out. I tried to use</p>
<pre><code>kubectl rollout status deployment name --namespace nsName
</code></pre>
<p>but its just stating the status. Even if there is an error in the deployment.yaml the task simply say that there is error and the rollout status is saying successfully rollout. Is there a way I make the pipeline fail when there is an error in the deployment or the pods aren't created ?</p>
<p>My Yaml Task</p>
<pre><code>- task: AzureCLI@2
  inputs:
    azureSubscription: ${{ parameters.svcconn }}
    scriptType: 'pscore'
    scriptLocation: 'inlineScript'
    inlineScript: |
      az aks get-credentials -n $(clusterName) -g $(clusterRG)
      kubectl apply -f '$(Pipeline.Workspace)/Manifest/deployment.yaml' --namespace=${{ parameters.NS }}
      kubectl rollout status deployment ***svc-deployment --namespace=${{ parameters.NS }}
</code></pre>

threeleggedrabbit
<p>Your <code>kubectl</code> commands are getting applied successfully to the cluster which means the YAML's are getting updated in the kube cluster and so you will not see an error with apply or rollout commands in your Azure pipelines.</p>
<p>It's your Kubernetes controller manager that is not able to apply the changes from the updated YAML.</p>
<p>In your inline script, you can add some sleep time and then read the pod running status.</p>
<p>You can get a pod name if you have added an app label in your deployment-</p>
<p><code>POD=$(kubectl get pod -l app=my-app -o jsonpath=&quot;{.items[0].metadata.name}&quot;)</code></p>
<p>For that pod then you can pull the running status -</p>
<p><code>STATUS=$(kubectl get pods -n default $POD -o jsonpath=&quot;{.status.phase}&quot;)</code></p>
<p>You can then manipulate the <code>STATUS</code> variable to manipulate the pipeline result.</p>
