Title: Specify build branch based on branch used in triggering pipeline Azure Devops
Tags: azure;azure-devops;azure-pipelines
Question: Say I have two pipelines: PL1 and PL2 and that PL2 is triggered by PL1. Say I ran PL1 on the master branch, I want PL2 to also get triggered for the master branch. When PL1 is triggered on another branch, like releases/X.X.X I want PL2 to also be triggered on the releases/X.X.X branch. Can I do that? Right now PL2 is always using master when it gets triggered


Here is the accepted answer: I tried to replicate the scenario.
First pipeline:
```trigger:
  - none

stages:
  - stage: first
    jobs: 
     - job: firstJob
       continueOnError: false
       steps:
         - bash: echo &quot;first from test branch&quot;
```
Second Pipeline:
```resources:
  pipelines:
  - pipeline: firstPipeline
    source: first-pipeline
    trigger:
     branches:
      include:
        - ${Build.SourceBranch}

stages:
  - stage: second
    jobs: 
     - job: secondJob
       steps: 
         - bash: echo Test-branch
```
I tested these from two different branches and each time the source code of second pipeline was picked up based on the first pipeline's branch.
PS: Both of my pipeline YAML are in same repository

Comment for this answer: Thank you, I had something similar but it wasnt working, this helped though!


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:12/20/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<azure><azure-devops><azure-pipelines>', 'Title': 'Specify build branch based on branch used in triggering pipeline Azure Devops', 'ViewCount': 129, 'id': 70425019, 'user_AboutMe': '', 'user_AccountId': 19179579.0, 'user_DisplayName': 'zaidabuhijleh', 'user_Reputation': 127.0, 'user_Views': 15.0, 'user_id': 14011616.0}}