3
votes

From: https://connect.microsoft.com/VisualStudio/Feedback/Details/2264644

According to: https://msdn.microsoft.com/en-us/library/vs/alm/build/scripts/variables

Build.SourceBranch should map to $/teamproject/branch and Build.SourceBranchName should map to "branch" where the full path is $/teamproject/branch

I have a branch structure like $/MyProject/Development/MyBranch and when I try to use these variables in PowerShell (i.e. using BUILD_SOURCEBRANCH and BUILD_SOURCEBRANCHNAME), I am getting:

BUILD_SOURCEBRANCH: $/MyProject BUILD_SOURCEBRANCHNAME: MyProject

From my understanding of the article, the variables should return $/MyProject/Development/MyBranch and MyBranch respectively.

Anyone else able to repro this behaviour with a TFVC repository? If you set up a vNext build definition with just a PowerShell task and add the following snippet, you'll be able to see the available variables in the output:

[CmdletBinding()]
param()
$environmentVars = get-childitem -path env:*
foreach($var in $environmentVars)
{
    $keyname = $var.Key
    $keyvalue = $var.Value

    Write-Output "${keyname}: $keyvalue"
}
1

1 Answers

3
votes

I have to modify the answer as I have new find. After double checking the MSDN article, I found for TFVC BUILD_SOURCEBRANCH will be the root server path for the workspace. So I tried mapping the branch path to Server Path, please refer to the screenshot below. After specifying the Server Path to the branch path, you will get correct value of BUILD_SOURCEBRANCH.

enter image description here