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:
- 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_ciand, if it has failed, trigger the rerun of the pipeline. - 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.