The main question is how to start a build when another build succeeds in Team Foundation Server (TFS)? In other words, how to invoke a TFS Build from another TFS Build? For related information on working with TFS, you can also read about Versioning Assembly with TFS Build 2013 and Creating and Deploying Web Package during TFS Build 2013, along with Creating a TFS Build Custom Activity to Read XML Files or Rolling back DB and Web Applications during TFS Builds.
A third-party library isn’t needed to do so, all I had to do is to edit the default Lab Management process template which has already done that (invoked a build from other build).
I copied the build process and removed most of the activities, variables, and arguments and did some modifications; the following is an image of all the processes, and I will explain what happens in each section:
Step 1: Build Definition
Here is the Build definition that uses the process; it only has 4 arguments, and we can see that the build definition arguments are a list of strings so we can point to many builds as needed. Also, we have the option to run builds in sequence if builds depend on each other, or disable in the case of no dependencies.
Step 2: Loop Additions
In the following section, I just added a loop for each that iterates over the list of given builds and invokes each one. Note here that I check if we want to run the build in sequence, see the next step.
Step 3: Build Sequence
If we want to run the build in a sequence (the condition is true) to make each build depend on the previous build status, so that if one build fails then the main build will stop and fail.
To do this, I wait until the build is finished and change the main build status (success or fail) and if it fails then the main build will stop and fail (ThrowOnError), if it succeeds, it goes to the next iteration in the loop (waits for the next build).
Step 4: Running the Build with No Dependencies
If we don’t want to run the build in sequence (condition is false), we just need to trigger all builds with no dependencies; this means the main build always succeeds even if other child builds fail because it’s not dependent on them. The main build may even finish while other builds are still running, so I made the main build wait for the last triggered build in the loop; but if the last build finishes before a previous one, the main build will finish before all of the builds are finished, so I changed (ThrowOnError) to be false so the main build will not fail if the last build fails.