VSTS Build: What branch am I building?

If you need to know the branch that you are running your build against, you can use Build.SourceBranchName Environment variable.

As described here: https://msdn.microsoft.com/en-us/library/vs/alm/build/scripts/variables

The name of the branch the build was queued for.

  • For Git this is the last path segment in the ref. For example inrefs/heads/masterthe name ismaster.
  • For TFVC this will last path segment in the root server path for the workspace. For example in $/teamproject/branch the name is branch

You can access the variable from PowerShell this way:


About esteban

Esteban is the Founder and Chief Technologist at Nebbia Technology, an ALM consulting and Azure-powered technology company. He is a software developer with a passion for ALM, TFS, Azure, and software development best practices. Esteban is a Microsoft Visual Studio ALM MVP and ALM Ranger, Pluralsight author, and the president of ONETUG (Orlando .NET User Group).

2 thoughts on “VSTS Build: What branch am I building?

  1. Visual Studio – Developer Top Ten for Apr 22nd, 2016 - Dmitry Lyalin

    […] VSTS Build: What branch am I building? by Esteban Garcia […]

  2. Saurabh bhasin


    What if you have common pipeline for different branches? How to know in which branch code has been commited?


Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? *