azure-devopsazure-pipelinescrontrigger

Scheduled trigger in Azure Pipeline multistage for a spesific stage


I have a multistage pipeline on Azure DevOps, and I would like to trigger one of the stages every night but the other stages would be triggered by changes in GitHub repo. I'm wondering if it is possible to use scheduled trigger for only one Stage, if so how? as I found in google, it seems it is only for entire pipeline. How is it possible to trigger only one Stage in a specific day and time?

Here is how the pipeline looks like:

name: Pipeline

trigger:
  branches:
    include:
      - master
      - refs/tags/v*

variables:

resources:
  repositories:

stages:
 - stage: Build
   jobs:
   - job: Build
     steps:

     pool:
       vmImage: 'ubuntu-latest'

 - stage: Deploy_Dev
   variables:

   jobs:
   - steps:

###Nightly triggered

 - stage: Deploy_Test
   variables:

   jobs:
   - steps:

Solution

  • I'm wondering if it is possible to use scheduled trigger for only one Stage, if so how? as I found in google, it seems it is only for entire pipeline. How is it possible to trigger only one Stage in a specific day and time?

    I am afraid there is no such out of box way to achieve that. As you know, it is only for entire pipeline.

    As workaround for this question, you could set UI defined scheduled triggers for this pipeline:

    enter image description here

    Then add a custom condition for the job of Deploy_Test stage:

     - stage: Deploy_Test
       jobs:      
       - job:
         condition: and(always(), eq(variables['Build.Reason'], 'Schedule'))
         steps:
    

    In this case, the stage only executed when the build triggered by scheduled trigger. If the build is triggered by changes in GitHub repo, the stage Deploy_Test stage will be skipped:

    enter image description here

    Note: The limitation of this workaround is that when your pipeline is triggered by a scheduled trigger, the stage build and Deploy_Dev are also executed.

    Hope this helps.