azure-devopsterraformazure-yaml-pipelines

Prevent Cancellation of Deployment Job on PR Changes


We have an Azure DevOps YAML multi-stage pipeline where code is built and then deployed to a sequence of environments. Deployment is achieved using Terraform.

i.e.

Builds -> Test -> Deploy to DEV -> Deploy to TEST - - ->

This pipeline is used for both CI/CD builds and also PR builds. For the PR build, the only part of the deployment stage is running terraform plan on the TF scripts.

For PRs, the pipeline is configured to cancel the ongoing build if changes are pushed to that PR.

The problem we're seeing is that when changes are pushed to the PR and the ongoing build is cancelled, sometimes that cancellation happens during the terraform plan step. This occasionally means that the blob lease taken by terraform plan is not released. From that point onwards, manual intervention is required (break the blob lease) in order for the deployment stages to run successfully.

I believe we can switch off the setting which causes the ongoing PR build to be cancelled if changes are pushed.

But I wondered if there was a way of marking a pipeline step as critical - i.e. it should run to completion if the build is cancelled?

There are other ways of cancelling a pipeline build and there must be other tasks/steps which should not be cancelled part-way through. Such a critical-task setting would cover these situations too.


Solution

  • I'm afraid you won't be able to achieve this using just YAML. What you can do will require some additional effort (and in some cases quite big):

    I understood that you would like to hear something better than this but at the moment there is no way to mark a task as non-cancellable. However, this sound like a cool feature and candidate for feature request.