How to reject the ADO pipeline execution, if approval doesn't provide

Anonymous
2025-07-14T14:42:18.31+00:00

We currently have a 30-day default approval timeout configured in the pipeline. However, we also need to ensure that if approval is not provided within this window, the pipeline run is automatically rejected or canceled to prevent it from continuing indefinitely.

Note: We are using YAML-based pipelines, tried below code but, didn't work**
**
User's image

We provided the approvals under environments, hence that environment / staging specific execution is skipped after timeout in multistage pipeline, but we want to cancel it, how can we achieve the same

User's image

Azure DevOps

Answer accepted by question author
Durga Reshma Malthi 11,375 Reputation points Microsoft External Staff Moderator
2025-07-14T15:26:42.0833333+00:00

Hi Rupali Bhore

Azure DevOps currently does not natively support auto-rejecting or canceling a run if an approval is not granted, it simply skips the environment after the timeout.

To force a cancellation or rejection if approval isn’t granted within the timeout window, you’ll need to use the ManualValidation@0 task inside an agentless job.

jobs:
- job: waitForApproval
  displayName: 'Wait for manual approval'
  pool: server  # agentless job
  timeoutInMinutes: 43200  # 30 days
  steps:
  - task: ManualValidation@0
    inputs:
      instructions: 'Please approve the deployment.'
      notifyUsers: |
        [email protected]
      onTimeout: 'reject'  # This will cancel the pipeline if approval isn't given
    timeoutInMinutes: 43200  # 30 days

Then, make your actual deployment job depend on this approval job:

- deployment: Deploy_${{ parameters.functionAppName }}
  dependsOn: waitForApproval
  environment: ${{ parameters.longName }}
  strategy:
    runOnce:
      deploy:
        steps:
        - script: echo "Deploying..."

The ManualValidation@0 task pauses the pipeline and waits for approval. If approval isn’t granted within the timeout, it explicitly rejects the run.

Hope this helps!

Please Let me know if you have any queries.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.