3

I have a recurring issue with an Azure Pipeline YAML template that cannot be cancelled once started. The template defines a release stage that includes 3 jobs:

stage: Release
  jobs:
    - job: Wait
       steps:
         - task: Delay@1
           inputs:
             delayForMinutes: ${{ parameters.ReleaseDelay }}
    - deployment: Deploy
      dependsOn: 
        - Wait
      # several more tasks that work fine 
    - job: Cleanup # works fine also
       

Our workflow is such that sometimes, we want to go ahead and approve a deployment, but we would like to queue it to wait for a couple hours, e.g. to prep updates to release after business hours. It works fine normally.

The issue comes if we try to cancel the Wait task through the pipeline Web UI. Once the release environment approval has been granted and the wait task has started, the pipeline execution cannot be cancelled.

I've tested this with multiple pipelines that reuse this template and it is a persistent/reproducible issue.


So, my question is, is the Microsoft built-in Delay task inherently un-interruptable, or is my dependency in the successor task somehow locking the Delay from being able to be cancelled?

The pipeline will show a status of "Cancelled" once I click the confirmation button to cancel the run, but the task continues to execute as if I had not done so. Crucially, it also does not cancel at the end of the Wait task. It will start straight into the deployment job as if it never received the order to cancel.

The Azure Pipelines docs do not mention the Delay task being un-interruptable, and I can cancel other tasks at different places in the pipeline which also have dependencies defined, so I don't think it's the fault of the dependency declaration, but that's also a secondary candidate for investigation.

bluemoon6790
  • 467
  • 2
  • 11
  • 1
    You can add a Business Hours check on your environment so that deployments cannot take place outside of specified time ranges. – Daniel Mann Jun 04 '22 at 12:39
  • The problem isn't getting it to run in business hours. The problem is cancelling the Delay task once it has begun. We had an approver approve a release that should not have been released, and we were unable to cancel it once that Delay task started. – bluemoon6790 Jun 06 '22 at 12:51
  • I'm saying that you can **remove** the delay task and use the business hours gate to control when a deployment can take place. – Daniel Mann Jun 06 '22 at 17:38
  • Well, yes, that would work from the info I gave you, but not all of our applications have the same release window, and some of them have different rules at different times of year because of the organization's busy season. It would be a better fit for our overall business requirements to get this problem fixed while keeping the configurable delay, if possible. – bluemoon6790 Jun 06 '22 at 21:44

1 Answers1

0

You could investigate using the manual validation task instead of the delay task

Using this you could set a timeout but have the ability to shortcut the timeout by resuming the pipeline. Set the task to "resume" once the timeout has been reached.

Your YAML would look something like this

stage: Release
  jobs:
    - job: waitForValidation
      displayName: Wait for external validation
      pool: server

      steps:
       - task: ManualValidation@0
         timeoutInMinutes: ${{ parameters.ReleaseDelay }}
         inputs:
           notifyUsers: |
             test@test.com
             example@example.com
           instructions: 'Please validate the build configuration and resume'
           onTimeout: 'resume'
  
    - deployment: Deploy
      dependsOn: 
      - waitForValidation
    # several more tasks that work fine 

    - job: Cleanup # works fine also
   

Note that this type of task can only be run on on an "Agentless" job so don't forget to set the pool on that job to "server" e.g. pool: server

James Reed
  • 13,873
  • 51
  • 60