0

Quite new to the CI/CD pipelines in AzDO. I was going through some official Azure Pipeline documents where I have some doubts on Schedule Triggers.

Below is a pipeline Snippet in main branch:

schedules:
- cron: "0 0 * * *"
  displayName: Daily midnight build
  branches:
    include:
    - main
    - releases/*
    exclude:
    - releases/ancient/*
- cron: "0 12 * * 0"
  displayName: Weekly Sunday build
  branches:
    include:
    - releases/*
  always: true

The documentation says the Pipeline will run for branches "main" and "releases" at midnight if there has been some changes to those branches since the last successful scheduled run and build the "releases" branch on sunday irrespective of changes to releases branch which seems understandable.

Which means we can control other branches (e.g. releases) to build from YAML file present in another branch (e.g. main).

Again, the documentation also states, for below YAML in a release branch

# YAML file in the release branch
schedules:
- cron: "0 0 * * *"
  displayName: Daily midnight build
  branches:
    include:
    - main

The pipeline won't build "release" branch since the branch name is missing under "branches" section. But will it build the "main" branch though since it's mentioned under "branches" section?

If no, then how can the first YAML in main branch make "releases" branches to build? Does the YAML file in main/default branch has some special capabilities?

If yes, does it really make sense to build "main" branch from release/non-main branches?

Thanks in advance.

Sandeep Kumar
  • 53
  • 1
  • 4

1 Answers1

0

If no, then how can the first YAML in main branch make "releases" branches to build? Does the YAML file in main/default branch has some special capabilities?

There's a setting for default branch in Azure Pipelines (Edit pipeline -> get sources -> Default branch for manual and scheduled builds) which tells the pipeline which branch to evaluate for scheduled runs. Yaml builds use the same scheduling that classic pipelines do and a changes to the yaml-file in that default branch are reflected in the scheduler.

Or to put it in another way, a pipeline in Azure DevOps is a separate thing from the yaml-file in repository. After creating a yaml-file in repo, you need to create a pipeline in Azure DevOps, via new pipeline -> select repo -> existing Azure Pipelines yaml file (or create a new yaml file). This step creates the actual pipeline, which has it's own configurations that are stored somewhere in Azure DevOps database. Those configurations point to the yaml file that is evaluated for pipeline runs and when the file is changed.

If you queue a pipeline manually, and select some other branch than the default, the yaml file in the branch that you selected is evaluated. Also, when evaluating branch triggers, pipeline evaluates the yaml file in the branch commit is made to. So, if you have this trigger in main branch:

trigger:
 - main
 - feature/*

And this in feature/foo -branch:

trigger:
 - main

A commit to the feature/foo branch does not trigger the pipeline.

(Not sure if I answered the question clearly or just added some confusion, but there you go. The trigger implementation in Azure Pipelines is a bit confusing at first.)

JukkaK
  • 1,105
  • 5
  • 15
  • Hmm.. If i understand it correctly, we need to setup build pipelines for non-default branches if we wish to trigger the pipeline upon commit to those non-default branches. However, if we don't mention the non-default branch name under "trigger" section in the YAML for non-default branch, it wouldn't trigger the pipeline. Now if we have let's say, mentioned both "main" and "features/foo" under the trigger section in the YML of a non-default branch(features/foo), any commit made to that branch will trigger the pipeline for both main and features/foo branch, correct? – Sandeep Kumar Oct 31 '21 at 08:42
  • You need to setup just one build pipeline, abd add the branches that should trigger from commit under the trigger. However, that yaml file should exists in all the branches that are supposed to be triggered. For scedhuled build, you should add the scedhule-trigger and set the default branch in pipeline settings to point main-branch. Again, the pipeline yaml-file should be present in other branches that the scedhule is supposed to trigger. – JukkaK Nov 01 '21 at 10:27