首页 > 解决方案 > PowerShell 脚本中的 TFS 2012 构建变更集版本

问题描述

我们有一个 TFS 2012 实例和一个带有 VS 2017 的构建代理。我正在尝试修改 XAML 构建模板以从给定项目创建一个 nuget 包。我需要将变更集编号放在包的描述中,但我无法获得正确的值。

我的模板的 AgentScope 中有一个 InvokeProcess 活动,它运行 PowerShell 脚本来打包包。我尝试获取 TF_BUILD_* 环境变量,但似乎没有填充。我也尝试了 BUILD_SOURCEVERSION ,但没有运气。目前我正在传递 BuildDetail.SourceGetVersion 值,但这是返回整个团队项目的当前变更集,而不是我正在构建的特定项目。

我究竟做错了什么?这些变量是否仅在 TFS 服务器上而不在代理(构建服务器)上?

标签: powershelltfstfsbuild

解决方案


TFS 2012 build changeset version in PowerShell script

According to the article Build Script Hooks for TFS 2012 Builds:

When I created a script for a 2013 build to version the assemblies, I relied on the fact that the 2013 build sets some environment variables that you can use in your scripts.You can see I’m getting $env:TF_BUILD_BUILDNUMBER. Well, in the 2012 workflow, these variables aren’t set, so you have to add an activity to do it.

That the reason why you tried getting the TF_BUILD_* environment variables but none seem to be populated.

So, to resolve this issue, you can just to follow the steps in Challenge 2 to set it.

Or, you can use TFS API to get the latest changeset number in your TFS version control:

Please see this thread for detailed information:

Programmatically retrieve the latest changeset number available in a workspace

Then you can write another small program to modify your description field in the .cs file be the changeset number you get in above.

Hope this helps.


推荐阅读