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:

Write-Host “Branch: $Env:BUILD_SOURCEBRANCHNAME”

Scroll to Top