-2

I'm working on the web services project on the Azure DevOps. I have written the yaml pipeline for build and release.

Currently I have kept the yaml file in Develop branch and created the pipeline job from same. As per the practice, we have two branches - Master & Develop. So how I can use single pipeline job for both the branches with auto trigger for develop and schedules base for main branch ? What is the best practice to build and deploy the code to DEV, UAT and PROD environments for Development and Master branches?

Ajit Medhekar
  • 1,018
  • 1
  • 10
  • 39
  • 1
    The YAML should be in every branch. When the pipeline runs via CI triggers, it will automatically check out the branch that triggered the run. – Daniel Mann Jun 22 '22 at 16:13

1 Answers1

1

Update:

You need to make sure the yaml file that the pipeline use exists in both master and Develop, otherwise the commit will not trigger the pipeline at all.

1, pure yaml trigger settings in one pipeline.

azure-pipeline.yml in Master branch:

trigger:
- none

schedules:
- cron: "53 7 * * *" 
  displayName: Master Schedule
  branches:
    include: 
      - master
  always: true 

pool:
  name: default

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

azure-pipeline.yml in Develop branch:

trigger:
- Develop

pool:
  name: default

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

2, pure UI settings in one pipeline.

enter image description here

enter image description here

Original Answer:

You can override the CI trigger of your pipeline.

Pipeline of develop branch:

enter image description here

enter image description here

Pipeline of master branch:

enter image description here

enter image description here

enter image description here

Bowman Zhu-MSFT
  • 4,776
  • 1
  • 9
  • 10
  • But here you have created 2 pipelines for Dev and Master. Is there a way like I'll create only one yaml pipeline and which will trigger for both Dev and Master depending on the commit to Dev or Master. The one scenario I'm trying in yaml is - trigger: batch: true branches: include: - master - development and using conditions, I can deploy to specific environments. But is this the correct way to use same pipeline for both Dev and Master branch. – Ajit Medhekar Jun 23 '22 at 07:01
  • @AjitMedhekar Hi, I updated the answer. You need to make sure the yaml file that the pipeline use exists in both master and Develop, otherwise the commit will not trigger the pipeline at all. Let me know if you have more concerns. – Bowman Zhu-MSFT Jun 23 '22 at 07:58
  • This is what I was looking and expecting. But I was not sure whether it's best practice or not to keep single Pipeline for multiple branches. – Ajit Medhekar Jun 23 '22 at 11:51