How to rerun the failed azure devops pipeline?

Helan Nivas 0 Reputation points
2025-12-20T13:19:17.1566667+00:00

Hello,

I have created an Azure DevOps pipeline that is scheduled to run weekly. Sometimes the pipeline fails due to a network blip, and I have to trigger it manually.

I want to build a solution to rerun the failed pipeline on the weekend only once. I don’t want it to rerun multiple times if the error occurs for a different reason.

From my research, it seems there are two possible options:

Service Hooks

Pipeline resource block

I have tried the Service Hooks method, but the pipeline triggers infinitely and it feels a bit complicated.

So, I thought of using the pipeline resource block in a monitoring pipeline YAML script. Below is the YAML script. However, it is not triggering after azure_pipeline_ci fails.

Does this mean the pipeline resource block will only work when the source pipeline succeeds?

trigger: none

pool:
  name: SelfHostedDemo

resources:
  pipelines:
  - pipeline: monitoring_pipeline
    source: 'azure_pipeline_ci'
    trigger: true

steps:
- task: PowerShell@2
  displayName: "Trigger Actual Pipeline if Failed"
Azure DevOps
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2025-12-20T13:19:29.6066667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To rerun a failed Azure DevOps pipeline only once on the weekend, you can utilize the pipeline resource block, but it is important to note that the resource trigger typically activates only when the source pipeline succeeds. This means that if azure_pipeline_ci fails, the monitoring pipeline will not trigger automatically based on the current configuration of your YAML script.

    To achieve your goal, you may need to implement a workaround. Here are some suggestions:

    1. Use a Scheduled Trigger: You can set up a scheduled trigger in your monitoring pipeline that runs at a specific time on the weekend. This pipeline can check the status of azure_pipeline_ci and, if it has failed, trigger the rerun of the pipeline.
    2. Implement Logic in the PowerShell Task: In your PowerShell task, you can use Azure DevOps REST API to check the status of the previous run of azure_pipeline_ci. If it failed, you can then trigger the pipeline programmatically using the API.

    Here’s an example of how you might modify your YAML to include a scheduled trigger:

    trigger: none
    
    schedules:
    - cron: "0 0 * * 0"  # Every Sunday at midnight
      displayName: "Weekly trigger"
      branches:
        include:
        - main
    
    pool:
      name: SelfHostedDemo
    
    resources:
      pipelines:
      - pipeline: monitoring_pipeline
        source: 'azure_pipeline_ci'
        trigger: false  # Disable automatic trigger on success
    
    steps:
    - task: PowerShell@2
      displayName: "Check Pipeline Status and Trigger if Failed"
      inputs:
        targetType: 'inline'
        script: |
          # Logic to check the status of azure_pipeline_ci and trigger if failed
          # Use Azure DevOps REST API here
    

    This approach allows you to run the monitoring pipeline weekly and check the status of the main pipeline, triggering it only if it has failed.

    0 comments No comments

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.