How to delay azure pipeline stage

Viewed 59

I have an azure pipeline that has 3 stages

  1. send notification to user that resources will be deleted

  2. request approval and wait 24 hours

  3. delete resource

I have the pipeline almost ready but i can't work around how to wait in the second stage for 24 hours the delay task timeouts after 60 Minutes and schedule function can't work for me because the pipeilne is triggered on other pipeline completion

schedules:
- cron: "31 17 * * *"
  displayName: every Every 24 hours execution for delete the aci if anything change in the branche main
  branches:
    include:
    - main
    - releases/*
    exclude:
    - releases/old/*

# Trigger this pipeline on model-train pipeline completion
trigger: none
resources:
  containers:
  - container: mlops
    image: mcr.microsoft.com/mlops/python:latest
  pipelines:
  - pipeline: deploy-to-aci-dev
    source: Deploy-to-aci-dev # Name of the triggering pipeline
    trigger:
      branches:
        include:
        - master

variables:
- template: estimation_engine-variables-template.yml
- group: devopsforai-aml-vg

stages:
- stage: 'Delay'
  displayName: 'Delay for 24 Hours'
  jobs:
  - job: "Send_notif_sendgrid"
    displayName: "send deletion notification for dev aci - sendgrid"
    pool:
      vmImage: 'windows-2019'
    timeoutInMinutes: 60
    steps:
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          Install-Module -Name PSSendGrid -Force
          Import-Module -Name PSSendGrid
          $Parameters = @{
              FromAddress     = "***************************"
              ToAddress       = "***************************"
              Subject         = "Dev-Aci sera supprimé dans 24 heures"
              Body            = "Azure container instance dans l'environnement Dev sera supprimé dans 24 Heures"
              Token           = "*******************************************"
              FromName        = "Pipeline Alert"
              ToName          = "DigitRE"
          }
          Send-PSSendGridMail @Parameters
- stage: 'DELETE_ACI'
  displayName: 'Delete Dev ACI'
  condition: variables['ACI_DEPLOYMENT_NAME_DEV']
  jobs:
  - job: "DELETE_ACI"
    displayName: "Delete Dev Aci"
    container: mlops
    timeoutInMinutes: 0
    steps:
    - task: AzureCLI@1
      displayName: 'Install AzureML CLI'
      inputs:
        azureSubscription: '$(WORKSPACE_SVC_CONNECTION)'
        scriptLocation: inlineScript
        inlineScript: |
          set -e # fail on error
          az container delete -n $(ACI_DEPLOYMENT_NAME_DEV) -g  $(RESOURCE_GROUP)  --yes -y ```

1 Answers

the delay task timeouts after 60 Minutes

For Microsoft host agent, It is impossible to occupy VMs indefinitely.

It is already clearly tell you here:

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?tabs=yaml&view=azure-devops#timeouts

Setting the value to zero means that the job can run:

1, Forever on self-hosted agents

2, For 360 minutes (6 hours) on Microsoft-hosted agents with a public project and public repository

3, For 60 minutes on Microsoft-hosted agents with a private project or private repository (unless additional capacity is paid for). aid parallel jobs remove the monthly time limit and allow you to run each job for up to 360 minutes (6 hours).

For your 24 hours requirement, the only way is using self host agent, but you are using Microsoft host agent.

schedule function can't work for me because the pipeilne is triggered on other pipeline completion

I think the two should be independent of each other. Why you think the latter influenced the former?

Follow these troubleshooting steps:

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=yaml#i-defined-a-schedule-in-the-yaml-file-but-it-didnt-run-what-happened

1, Check the next few runs that Azure Pipelines has scheduled for your pipeline. You can find these runs by selecting the Scheduled runs action in your pipeline. The list is filtered down to only show you the upcoming few runs over the next few days. If this doesn't meet your expectation, it's probably the case that you've mistyped your cron schedule, or you don't have the schedule defined in the correct branch. Read the topic above to understand how to configure schedules. Reevaluate your cron syntax. All the times for cron schedules are in UTC.

2, Make a small trivial change to your YAML file and push that update into your repository. If there was any problem in reading the schedules from the YAML file earlier, it should be fixed now.

3, If you have any schedules defined in the UI, then your YAML schedules aren't honored. Ensure that you don't have any UI schedules by navigating to the editor for your pipeline and then selecting Triggers.

4, There's a limit on the number of runs you can schedule for a pipeline.

5, If there are no changes to your code, they Azure Pipelines may not start new runs.

Let me know whether the above can help you more clearly understand.

Related