简体   繁体   中英

TFS 2013 Branch Name in MSBuild Script

I've seen several mentions of variables holding the TFS branch name, pulled from the last directory in the Source Settings path of the build definition, but I've not gotten any to work in TFS 2013. Is there a variable that will populate in my MSBuild script(triggered from the build definition) in TFS 2013?

This is what I've tried with no luck, all are blank:

<Message Text="SourceBranchName: $(SourceBranchName)" />    
<Message Text="Build.SourceBranch: %(Build.SourceBranch)" />
<Message Text="BranchName: $(BranchName)" />
<Message Text="Build.SourceBranchName: %(Build.SourceBranchName)" />
<Message Text="BUILD_SOURCEBRANCHNAME: $(BUILD_SOURCEBRANCHNAME)" />

Environment variable data in MSBuild script with TFS2013 do not use that kind of format.

It should be TF_BUILD_XXX such as

TF_BUILD_BUILDDIRECTORY: The build agent working directory. For example: C:\\Build\\BuildBot3\\CoolApp\\CIBuild.

The official tutorial with XAML build in TFS2013, you could refer this link-- Team Foundation Build environment variables .

As you can see, we do not have an Environment variable related to branch name used in build.

For a workaround, you could use client API to fetch similar info.

There is a property within an IBuildDetail object called SourceGetVersion . When a build definition is manually executed or triggered using the default branch defined in the build definition, then this property simply returns ' T ', but if the build definition was triggered by a commit to a monitored branch, then this property is set to the branch name.

Simply parse the value of this property and you should be able to determine exactly which branch triggered the build definition. Or you could also use

TF_BUILD_SOURCEGETVERSION: The version (TFVC changeset or Git commit) being built.

You're looking at the documentation for the build system introduced in TFS 2015. TFS 2013 only supported XAML build, which is deprecated and thus increasingly difficult to find documentation about.

There is documentation available, however.

The problem here is that you're looking for a variable that doesn't exist in TFS 2013. The best you can do is TF_BUILD_SOURCEGETVERSION , which will be either the TFVC changeset or the Git commit hash being built.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM