Multi branch Pipeline in Azure Devops

11.1k Views Asked by At

I am trying to build a YAML release pipeline in Azure DevOps for that I have created multiple branches to keep environment-specific files

first image

I created 4 pipelines for release as well:

second image

Problem: Whenever I am making any changes in any branch, all the branch pipeline starts running. If I run an individual pipeline it works fine.

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- acc

pool:
  name: 'Agent'

steps:

- task: Kubernetes@1
  displayName: 'Deploy on  K8s Cluster'
  inputs:
    connectionType: 'Azure Resource Manager'
    azureSubscriptionEndpoint: 'vs-aks-sc'
    azureResourceGroup: 'azwe-rg-01'
    kubernetesCluster: 'azwe-aks-01'
    command: 'apply'
    arguments: '-f $(System.DefaultWorkingDirectory)/kubernetes/acc.yaml'

third

deploy

3

There are 3 best solutions below

2
On BEST ANSWER

You should check the CI trigger setting of the pipeline to only allow it to trigger on your wanted branches

Change CI Trigger

1
On

Problem: Whenever I am making any changes in any branch, all the branch pipeline starts running.

If you just want to run the corresponding pipeline of the branch you modified, you need to make sure set the pipeline with the YAML file in the corresponding branch and set the correct branch trigger.

For example, for the Acc branch:

We need create a YAML file under the branch Feature/TestSample-acc with the branch trigger in the YAML file:

trigger: 
  branches:
    include:
      - Feature/TestSample-acc

enter image description here

Then create a pipeline with existing Azure pipeline YAML file:

New Pipeline-> Azure Repos Git(YAML)-> Select your repository-> Select existing Azure pipeline YAML file:

enter image description here

Now, this pipeline only triggered by the modification on the branch Feature/TestSample-acc:

enter image description here

You could set the same this for other branches, like

trigger: 
      branches:
        include:
          - Feature/TestSample-dev

Besides, if you do not want to control the trigger by the YAML file, you could override it by the UI trigger settings:

enter image description here

This option is disable by default, so that we could control the trigger in the YAML file directly.

If you enable it, you just need to add the Branch filters for just one branch:

enter image description here

If I am not understand your question correctly, please let me know for free that what you want to achieve.

0
On

The answer by "Leo Liu-MSFT" is correct.

BUT you also need to make sure that on each branch the YAML file has a different name, otherwise a commit to a single branch triggers more than one pipeline build.