'how to exclude build all branches except master branch in Azure Pipelines?

Currently my pipeline always runs builds on other branches, My expectation is that my pipeline only need to run build of a single branch which is master branch only.

Trigger from my yml is simply like this

enter image description here How do I need to change the yml so that it can be achieved as expected?



Solution 1:[1]

If you want the YAML build pipeline can only be triggered form the master branch, you can try with the things:

  1. Only keep the YAML file on the master branch. And make sure the branches filter on the trigger only include master.

    trigger:
      branches:
        include:
        - master
    
  2. If you cannot only keep the YAML file on the master branch, make sure the YAML file on each branch has the same branches filter as above.

  3. Set the trigger from the settings page and only include the master branch. With this way, the triggers set in the YAML files will be overridden by that on the settings page.

    enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 avazula