azure-pipelines-agent: Variable $(Build.Repository.Name) not working as expected

I am trying to setup a cross-repository policy and have written a build validation pipeline. The checkout step I am using is as follows - checkout: git://Project-Name/$(Build.Repository.Name)@$(Build.SourceBranch)

Whenever there is a pull request in any repository of my project this pipeline will trigger. In my case $(Build.SourceBranch) is referring to the pull request and that’s what I want, but $(Build.Repository.Name) is referring to the name of the pipeline repo instead of the triggering repo.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I would suggest to reopen this as the bug still exists. Documentation for Build variables mentions that Build.Repository.Name should contain “The name of the triggering repository” - but instead it is the name of the repository where pipeline yaml is defined.

I would assume you can’t change the value but at least fix the documentation. Workaround on getting the triggering repository name from System.PullRequest.SourceRepositoryURI only works for pull request builds - not e.g. CI builds as others have mentioned.