How to chain TFS builds?

user22242 picture user22242 · Jul 24, 2009 · Viewed 8.3k times · Source

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.

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?

Answer

Richard Berg picture Richard Berg · Jul 24, 2009

It depends what you are trying to do.

1) Do you want the build + staging to run as one operation? So that you end up with one consolidated build report, one log file, one job in the server's build queue, every step executed sequentially by the same Build Agent that executed the previous step?

If so, then you are on basically the right path. I wouldn't <Exec> out to tfsbuild.exe though -- running an entire new build has a lot of overhead, and I'm not sure what the potential side effects are. Instead, I would use the <Call> task to execute msbuild tasks defined in your staging script(s).

2) Do you want the "build build" to actually queue a separate "staging build"? Separate reports, log files, & spots in the queue? Opportunity to be executed in parallel if you have multiple Build Agents?

If so, then:

  • create a new build definition(s) for staging
  • add some code to your original build definition that queues [one/several] of the new build definitions using the Team Build API. Sample code.
  • remove anything not related to the core build from the original build definition
  • make sure the new "staging" definitions don't have any automatic triggers (time intervals, checkin events, etc)