4

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

fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
Satyam Pandey
  • 593
  • 2
  • 10
  • 32
  • can you share your YAML files? probably the issue is there. – Shayki Abramczyk May 05 '21 at 11:01
  • What you mean "If i run individual pipeline it work fine."? Manually run each pipeline? – Leo Liu May 06 '21 at 02:24
  • Yes if i manually run each pipeline it work fine, howver if i change anything in branches present in azure repo all branch run the same pipeline – Satyam Pandey May 06 '21 at 03:19
  • @SatyamPandey, Thanks for your reply. Need to confirm one more things, you said all branch run the **same** pipeline instead of "all the branch pipeline starts running", that mean those four branch run the same pipeline rather than their respective pipelines, am I right? – Leo Liu May 06 '21 at 03:27
  • Yes all the branches starts running the same pipeline, – Satyam Pandey May 06 '21 at 03:32
  • @SatyamPandey, you need make sure all those four pipeline use the respective YAML file used by the pipeline and the branch trigger set is the respective branch. For example, the pipeline `Deploy to Prod K8S Cluster` pipeline need use the YAML under the branch `Pord` and the branch trigger should be `trigger: - Prod` – Leo Liu May 06 '21 at 03:39
  • Yes i have did the same how ever let me delete the pipeline and recreate the same – Satyam Pandey May 06 '21 at 03:43
  • @Satyam Pandey, How about the issue? Does the answer below resolved your question, If not, would you please let me know the latest information about this issue? – Leo Liu May 07 '21 at 09:29

3 Answers3

7

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.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
1

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

Change CI Trigger

lylam
  • 46
  • 1
0

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.