Reputation: 493
In Azure DevOps, I have some pipelines in yaml files that execute tasks in Terraform and PowerShell to deploy infrastructures in Azure.
I would like to trigger a default action (like printing a default error message or delete somethings, etc.) if there is an error during the deployment, no matter if the error is from a Terraform script or PowerShell.
I think that the Yaml file can handle this action, but how?
Upvotes: 3
Views: 8479
Reputation: 9218
You can do this by adding a task at the end of your deployment job with a special condition to make sure it runs only if the pipeline has failed; the docs explain the use of these kinds of condition:
You can specify conditions under which a step, job, or stage will run.
- Only when all previous dependencies with the same agent pool have succeeded. If you have different agent pools, those stages or jobs will run concurrently. This is the default if there is not a condition set in the YAML.
- Even if a previous dependency has failed, unless the run was canceled. Use
succeededOrFailed()
in the YAML for this condition.- Even if a previous dependency has failed, even if the run was canceled. Use
always()
in the YAML for this condition.- Only when a previous dependency has failed. Use
failed()
in the YAML for this condition.
Upvotes: 3