简体   繁体   English

TFS 2012构建PowerShell脚本中的更改集版本

[英]TFS 2012 build changeset version in PowerShell script

We have a TFS 2012 instance and a build agent w/ VS 2017. I am trying to modify a XAML build template to create a nuget package from a given project. 我们有一个TFS 2012实例和一个带VS 2017的构建代理。我正在尝试修改XAML构建模板,以从给定项目创建nuget包。 I am required to put the changeset number in the description of the package but I am unable to get the correct value. 我需要将变更集编号放在软件包的说明中,但我无法获得正确的值。

I have an InvokeProcess activity in the AgentScope of my template which runs a PowerShell script to pack the package. 我的模板的AgentScope中有一个InvokeProcess活动,该活动运行PowerShell脚本来打包程序包。 I have tried getting the TF_BUILD_* environment variables but none seem to be populated. 我尝试获取TF_BUILD_ *环境变量,但似乎没有一个被填充。 I also tried BUILD_SOURCEVERSION with no luck. 我也尝试过BUILD_SOURCEVERSION,但没有运气。 At the moment I am passing in the BuildDetail.SourceGetVersion value but that is returning the current changeset for the entire team project, not the specific project I am building. 目前,我传递的是BuildDetail.SourceGetVersion值,但这将返回整个团队项目的当前变更集,而不是我正在构建的特定项目。

What am I doing wrong? 我究竟做错了什么? Are those variables only on the TFS server and not on the agent (build server)? 这些变量是否仅在TFS服务器上而不在代理(构建服务器)上?

TFS 2012 build changeset version in PowerShell script TFS 2012构建PowerShell脚本中的更改集版本

According to the article Build Script Hooks for TFS 2012 Builds : 根据文章TFS 2012构建的构建脚本挂钩

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. 当我为2013年版本创建脚本以对程序集进行版本控制时,我依靠2013年版本会设置一些可在脚本中使用的环境变量这一事实,您会看到我正在获取$ env:TF_BUILD_BUILDNUMBER。 Well, in the 2012 workflow, these variables aren't set, so you have to add an activity to do it . 嗯, 在2012年工作流程中,这些变量没有设置,因此您必须添加一个活动来执行此操作

That the reason why you tried getting the TF_BUILD_* environment variables but none seem to be populated. 这就是为什么您尝试获取TF_BUILD_ *环境变量但没有一个被填充的原因。

So, to resolve this issue, you can just to follow the steps in Challenge 2 to set it. 因此,要解决此问题,您只需按照“挑战2”中的步骤进行设置即可。

Or, you can use TFS API to get the latest changeset number in your TFS version control: 或者,您可以使用TFS API在TFS版本控件中获取最新的变更集编号:

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. 然后,您可以编写另一个小程序来修改.cs文件中的description字段,使其成为上面获得的变更集编号。

Hope this helps. 希望这可以帮助。

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

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