如何链接TFS构建? [英] How to chain TFS builds?

查看:139
本文介绍了如何链接TFS构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我想从另一个调用一个TFS构建,第一个进行构建,第二个进行暂存.这样一来,我就可以针对同一解决方案进行多个自定义登台.

I have a scenario where I want to call one TFS build from another, the first one does the build and the second one does staging. This will allow me do multiple custom staging for the same solution.

我知道,我可以在第二个构建中使用exec任务来完成此任务,然后调用tfsbuild.exe将第一个构建定义中的构建排队.但是想知道是否有人知道更好的方法吗?

I know, I can pull this off with an exec task in the second build and call tfsbuild.exe to queue a build from the first build definition. But was wondering if someone knew of a better way?

推荐答案

这是我完成此操作的方式(

Here is how I accomplished this (http://sajojacob.com/2009/08/how-to-chain-tfs-builds/)

如何链接TFS构建? 由Sajo于2009年8月5日发布-没有评论↓

How to Chain TFS Builds? Posted on August 5, 2009 by Sajo — No Comments ↓

我的一位同事@gdurzi最近问了我这个问题.听起来很简单,可以使用TFS开箱即用地支持吗?对此有太多怪癖.而且我建议使用永远忠实的MSBuild任务来调用TFSBuild.exe,以将第一个TFSBuild.proj中的新构建与这样的东西排队

One of my colleagues @gdurzi recently asked me this question. Sounds straightforward enough to be supported out of the box with TFS right? Too many quirks with this. And I recommended using the ever faithful MSBuild task to make a call to TFSBuild.exe to queue a new build from the first TFSBuild.proj with something like this

TFSBuild.exe开始/队列%TFSSVR%%TEAMPROJECT%%BUILDTYPE%

TFSBuild.exe start /queue %TFSSVR% %TEAMPROJECT% %BUILDTYPE%

使用TFSBuild.exe的一个问题是您不能将Build代理作为命令行参数传递给我们,这对我们来说是一个问题.

An issue with using TFSBuild.exe is that you cannot pass Build agents as a command line argument which was a deal breaker for us.

您可以根据您的特定方案采取多种方法,因此让我们在此处定义方案,您有一个Main_Build TFS构建定义来构建您的核心项目,并且您希望能够具有多个运行相同Main_Build的临时构建的能力.编译/构建,但可以根据谁调用Main_Build进行定制部署.当您有一个产品可以推广到多个客户端,并且每个客户端需要自定义的构建前和构建后操作时,此功能非常有用.因此,这是使用TFS 2008建立链接的一种方法.

There are several approaches that you can take based on your particular scenario so let’s define the scenario here, you have a Main_Build TFS build definition that builds your core project and you want the ability to have multiple staging builds running the same Main_Build for compilation/building, but be custom staged for deployment based on who calls Main_Build. Very useful when you have a product which rolls out to multiple clients with a need for custom pre-build and post-build actions per client. So here is one way to do Build Chaining with TFS 2008.

步骤1:让我们使用Team Foundation对象模型创建自定义MSBuild任务,该模型使用与构建定义文件相关联的默认构建代理将构建排入队列.

Step 1: Let’s create a custom MSBuild task using the Team Foundation object model which queues a build using the default build agent associated with the Build definition file.

排队的示例代码:QueueTFS.cs

Sample code for Queuing: QueueTFS.cs

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Build.Client;

// Get the team foundation server. 
TeamFoundationServer _tfsServer = TeamFoundationServerFactory.GetServer(_tfs); 

// Get the IBuildServer 
IBuildServer buildServer = (IBuildServer)_tfsServer.GetService(typeof(IBuildServer)); 

// Get the build definition for which a build is to be queued. 
IBuildDefinition definition = buildServer.GetBuildDefinition(teamProject, buildDefinition); 

// Create a build request for the build definition. 
IBuildRequest request = definition.CreateBuildRequest(); 
request.CommandLineArguments = "Pass any custom command line args here"; // Ex: Custom Targets file

// Queue the build. 
buildServer.QueueBuild(request, QueueOptions.None);

步骤2:现在将QueueTFS.dll复制到您要在其中创建临时构建定义文件的TFS中的新文件夹中.

Step 2: Now copy the QueueTFS.dll to a new folder in TFS where you want to create the staging Build definition file.

现在,我们创建一个最小的TFSBuild.proj文件,该文件使用我们的新MSBuild任务并覆盖EndToEndIteration目标.这将是我们的Staging构建定义,它将触发Main_Build构建.请注意,您将必须手动创建此TFSBuild.proj,只需将项目文件位置从构建定义"用户界面指向新文件夹即可.

Now let’s create a minimal TFSBuild.proj file which uses our new MSBuild task and overrides the EndToEndIteration target. This will be our Staging build definition which will trigger the Main_Build build. Note that you will have to create this TFSBuild.proj by hand and simply point the project file location from the Build definition UI to the new folder.

最小的TFSBuild.proj的示例代码:

Sample code for a minimal TFSBuild.proj:

<?xml version="1.0" encoding="utf-8"?> 
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> 
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" /> 
  <UsingTask TaskName="MyNewCustomTFSTask" AssemblyFile="QueueTFS.dll"/> 
  <Target Name="EndToEndIteration"> 
    <Message Text="About to trigger main build" Importance="high"/> 
    < MyNewCustomTFSTask TFS="http://TFSServer.com:8080/" TeamProject="TeamProject" BuildDefinition="Main_Build" TargetsFile="Custom.Target" XYZ="XYZ" /> 
    <!-- When everything is done, change the status of the task to "Succeeded" --> 
    <SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" TestStatus="Succeeded" CompilationStatus="Succeeded"/> 
  </Target> 
</Project>

第3步:使用构建前和构建后目标调用编辑Main_Build TFSBuild.proj文件.

Step 3: Edit your Main_Build TFSBuild.proj file with the pre-build and post-build target calls.

  <Target Name="BeforeCompile">

    <CallTarget Targets="Custom_PreBuild"/>    

  </Target>

  <Target Name="AfterDropBuild" Condition="‘$(BuildBreak)’!=’true’">    

    <CallTarget Targets="Custom_PostBuild"/>

  </Target>

我们还希望能够单独运行Main_Build,为此要支持此功能,我们在Main_Build TFSBuild.proj中添加了条件导入,以导入具有空Custom_PreBuild和Custom_PostBuild目标的默认目标文件. $(CustomTarget)是您在步骤1中作为request.CommandLineArguments

We wanted the ability to run Main_Build by itself as well, to support this we add conditional imports in our Main_Build TFSBuild.proj to import a default targets file with empty Custom_PreBuild and Custom_PostBuild targets. $(CustomTarget) is what you would pass as a command line argument in Step 1 for request.CommandLineArguments

<Import Project="$(CustomTarget)" Condition="'$(CustomTarget)'!=''"/>
<!--Import CustomContoso.Target if no partner is passed in—>
<Import Project="EmptyCustom.Target" Condition="'$(CustomTarget)'==''"/> 

第4步:现在,使用Custom_PreBuild和Custom_PostBuild目标创建目标文件Custom.Target和EmptyCustom.Target.

Step 4: Now create your targets file Custom.Target and EmptyCustom.Target with Custom_PreBuild and Custom_PostBuild targets and you are done.

我增加了对更新构建步骤和其他一些次要内容的支持,这些内容超出了本博客文章的范围,但这希望可以帮助您入门.

I added support for updating build steps and a few other minor things which outside the scope of this blog post, but this should hopefully get you started.

这篇关于如何链接TFS构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆