question

JeremyMorton-8016 avatar image
0 Votes"
JeremyMorton-8016 asked TymofiiOrlov-4127 published

Can't determine pipeline which triggered a build

I'm using Azure DevOps's multiple repository functionality, documented here:

https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops

I have my YAML file in one repo, and the pipeline points to that YAML. The YAML has a trigger set up for another repository resource, so that when that repo gets updated, the pipeline will be triggered:

 resources:
   repositories:
   - repository: MyRepo
     endpoint: 'MyRepos'
     type: git
     name: RepoName
     trigger:
     - '*'

The documentation claims that the 'Build.SourceBranch' variable will allow me to determine which branch in MyRepo triggered the pipeline build: "When an update to one of the repositories triggers a pipeline, then the following variables are set based on triggering repository"

However, this doesn't seem to be the case. No matter what branch triggers the build, 'Build.SourceBranch' is always 'refs/heads/master', presumably because the repo that holds the YAML has 'master' as its default branch.

I can't find any environment variable that gets set to the name of the branch that triggered the build, either. So how can I get the name of the branch that triggered the build? If there's no possible way, I think this needs to be added!

not-supported-azure
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks! The issue more related to Azure DevOps and It's better to reach out to below dedicated forum
Azure DevOps forum


0 Votes 0 ·

1 Answer

TymofiiOrlov-4127 avatar image
0 Votes"
TymofiiOrlov-4127 answered TymofiiOrlov-4127 published

You need to specify it as env variable in script:
- bash: echo Branch is $MAIN_BRANCH
env:
MAIN_BRANCH: $(Build.SourceBranch)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.