Passing branch names between pipelines

So far I was using the below pipeline which triggers the main pipeline. It tracks the pushed tags by developer to the master branch, and if so, starts running.

first_pipeline.yml

trigger:
  tags:
    include:
      - '*'
  paths:
    include:
      - master

variables:
  agent_pool: 'DEVAGENT'

pool:
  name: $(dev_pool)

The above pipeline triggers that one:

main_pipeline.yml

trigger: none
pr: none

resources:
  repositories:
    - repository: Grand
      type: git
      name: Automotive/Grand
      ref: master
      endpoint: Grand
    - repository: CICD
      type: git
      name: pipelines
      ref: master
  pipelines:
    - pipeline: Grand
      source: 'Grand'
      project: Automotive
      trigger: true

variables:
  - template: variables.yml

stages:
    - stage: DEV
      displayName: 'Development'
      variables:
        - name: environment
          value: ${{ variables.env_dev}}
      pool:
        name: ${{ variables.agent_dev }}
      jobs:
        - deployment: DEV
          displayName: 'Deploying to DEV'
      # Rest of the code   
  - stage: PRD
    displayName: 'Production Stage'
    variables:
      - name: environment
        value: ${{ variables.prd }}
    pool:
      name: ${{ variables.agent_prd }}
    jobs:
      - deployment: PRDDeploy
        displayName: 'Deploying to PRD'
    # Rest of the code

Above pipeline deploys changes to DEV stage, and than to PRD stage.

Now I’m trying to modify the pipeline to work in such a way that, for example:

  • when a change comes from the dev or deploy branch, then only the DEV stage will be run
  • when a change comes from feature or hotfix branches, it will go directly to PRD
  • when it comes from master as it has been until now, then it will go
    to both DEV and PRD.

So far it works only with the last condition, my first attempt leads to errors, because I am not sure how to pass those branch names from the first to main pipelines and modify that second one.

4

When you use the pipeline.resources.repository.trigger there are additional pipeline variables available:

resources.pipeline.<Alias>.projectName
resources.pipeline.<Alias>.projectID
resources.pipeline.<Alias>.pipelineName
resources.pipeline.<Alias>.pipelineID
resources.pipeline.<Alias>.runName
resources.pipeline.<Alias>.runID
resources.pipeline.<Alias>.runURI
resources.pipeline.<Alias>.sourceBranch
resources.pipeline.<Alias>.sourceCommit
resources.pipeline.<Alias>.sourceProvider
resources.pipeline.<Alias>.requestedFor
resources.pipeline.<Alias>.requestedForID

Based on your triggers, it looks like you’re using either a “tag” or commits to “master” to trigger the pipeline. You should be able to use $(resources.pipeline.Grand.sourceBranch) to get the originating branch. According to this answer, when a build is triggered by a tag, the sourceBranch will start with /refs/tags/<tag-name>.

Based on this, you should be able to do something like the following:

#first pipeline
trigger:
  tags:
    include:
    - '*'
  branches:
    include:
    - master

...


```yaml
# main_pipeline.yml
trigger: none

resources:
  pipelines:
  - pipeline: Grand # this is the alias
    source: 'Grand'
    project: Automotive
    trigger: true

stages:
- stage: dev
  condition: |
    or(
      startsWith(variables['resources.pipeline.Grand.sourceBranch', 'refs/tags/dev'),
      eq(variables['resource.pipeline.Grand.sourceBranch', 'refs/heads/master')
      )
  ...

- stage: prod
  condition: |
     or(
      startsWith(variables['resources.pipeline.Grand.sourceBranch', 'refs/tags/feature'),
      eq(variables['resource.pipeline.Grand.sourceBranch', 'refs/heads/master')
     )
  ...

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật