简体   繁体   English

MSBuild脚本中的TFS 2013分支名称

[英]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? 我已经看到几个提到的变量持有TFS分支名称,从构建定义的源设置路径中的最后一个目录中提取,但我没有在TFS 2013中工作。是否有一个变量将填充在我在TFS 2013中的MSBuild脚本(从构建定义触发)?

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. 使用TFS2013的MSBuild脚本中的环境变量数据不使用这种格式。

It should be TF_BUILD_XXX such as 它应该是TF_BUILD_XXX

TF_BUILD_BUILDDIRECTORY: The build agent working directory. TF_BUILD_BUILDDIRECTORY: 构建代理工作目录。 For example: C:\\Build\\BuildBot3\\CoolApp\\CIBuild. 例如:C:\\ Build \\ BuildBot3 \\ CoolApp \\ CIBuild。

The official tutorial with XAML build in TFS2013, you could refer this link-- Team Foundation Build environment variables . 在TFS2013中使用XAML构建的官方教程 ,您可以参考此链接 - Team Foundation Build环境变量

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. 对于变通方法,您可以使用客户端API来获取类似的信息。

There is a property within an IBuildDetail object called SourceGetVersion . IBuildDetail对象中有一个名为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. 当使用构建定义中定义的默认分支手动执行或触发构建定义时,此属性只返回' T ',但如果构建定义是由对受监视分支的提交触发的,则此属性设置为分店名称。

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. TF_BUILD_SOURCEGETVERSION: 正在构建的版本(TFVC变更集或Git提交)。

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. 您正在查看TFS 2015中引入的构建系统的文档.TFS 2013仅支持XAML构建,该构建已弃用,因此越来越难以找到有关的文档。

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. 这里的问题是你正在寻找TFS 2013中不存在的变量。你可以做的最好的是TF_BUILD_SOURCEGETVERSION ,它将是TFVC变更集或正在构建的Git提交散列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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