views:

732

answers:

2

How would you manually trigger additional team builds from a team build? For example, when we were in CC.Net other builds would trigger if certain builds were successful. The second build could either be projects that use this component or additional, long running test libraries for the same component.

+4  A: 

One way you could do it is you could an an AfterEndToEndIteration target to your TFSBuild.proj file that would runs the TfsBuild.exe command line to start you other builds. I'm thinking something like this (though I haven't tested it)

  <Target Name="AfterEndToEndIteration">

    <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
                        BuildUri="$(BuildUri)"
                        Condition=" '$(IsDesktopBuild)' != 'true' ">
      <Output TaskParameter="Status" PropertyName="Status" />
    </GetBuildProperties>

    <Exec Condition=" '$(Status)'=='Succeeded' "
          Command="TfsBuild.exe start /server:$(TeamFoundationServerUrl) /buildDefinition:&quot;Your Build Definition To Run&quot;" />

  </Target>
Martin Woodward
+3  A: 

I've done the same thing Martin suggested on a number of occasions (his blog is beyond helpful, BTW). However, I ended up needing to trigger cascading builds like this (based on some other complicated rules) enough that I created a custom task to do it. Keep your build scripts nice and lean and gives you some more flexibility and encapsulation possibilities.

 public override bool Execute()
 {  
  IBuildDefinition[] buildDefinitions = BuildServer.QueryBuildDefinitions(ProjectName);

  foreach (IBuildDefinition build in buildDefinitions)
  {
            if(build.Enabled) //I did a bunch of custom rules here
            {
                Log.LogMessage(String.Concat("Queuing build: ", build.Name));
                BuildServer.QueueBuild(build);
            }
  }

        return true;
 }

There's some more good stuff on Aaron Hallberg's blog too:

http://blogs.msdn.com/aaronhallberg/archive/2007/04/24/team-build-object-model-queueing-a-build.aspx

joshua.ewer