0
votes

In ADO, you can create a "repository resource" per this documentation. The "trigger" section allows you to define a CI trigger for any Azure repo in your space. Therefore, given the following config:

Repos:

  • AzureRepo1 - Contains project files that should be built
  • AzureRepo2 - Contains pipeline file 'pipeline.yml'
resources:
  repositories:
    - repository: "Azure_Repo_1"
      type: git
      name: AzureRepo1
      ref: development
      trigger: 
        branches:
          include: 
            - development
            - staging
            - production

pool:
  vmImage: 'windows-latest'

jobs:
- template: Template.yml
  parameters:
    service: "development"
    run_tests: true

When I make a change to AzureRepo1, the pipeline triggers. At runtime, how would I determine which branch ("production", "staging", or "development") of the target repo (AzureRepo1) triggered the build? Ideally, the "service" parameter being fed into the example template would dynamically reflect which branch triggered the build.

Note: "Build.SourceBranch" and "Build.SourceBranchName" seem to pull the branch from the repo that hosts the YML file (in this case, AzureRepo2).

I was wrong. These function as intended. Use the below solution.

1

1 Answers

0
votes

According to documentation here:

When an update to one of the repositories triggers a pipeline, then the following variables are set based on triggering repository:

  • Build.Repository.ID
  • Build.Repository.Name
  • Build.Repository.Provider
  • Build.Repository.Uri
  • Build.SourceBranch
  • Build.SourceBranchName
  • Build.SourceVersion
  • Build.SourceVersionMessage

For the triggering repository, the commit that triggered the pipeline determines the version of the code that is checked out. For other repositories, the ref defined in the YAML for that repository resource determines the default version that is checked out.

If triggers happens on AzureRepos1 you should have correct branch name in Build.SourceBranchName

enter image description here