Over a million developers have joined DZone.

Create One Main Build Process to Invoke Other Builds

Automate your TFS builds by learning to invoke a TFS build from another TFS build.

· DevOps Zone

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

The main question was…How to start a build when another build succeeds in TFS. In other words...how to invoke a TFS build from another TFS build?

I don’t need to use any third-party library to do so, all I had to do is to edit the default Lab Management process temple which already does that (invoke a build from other build).

I copied the build process and removed most of the activities, variables and arguments and made some modifications. The following is an image of all the processes and I will explain what happened in each section:
Master Build run other builds all the process

Here is the build definition that uses the process. It only has 4 arguments. We can see that build definitions arguments is a list of strings so we can point to many builds as needed, also we have the option to run build in sequence if builds depend on each other or disable that in case there are no dependencies.

Master Build run other builds-build definition

In the following section, I just added a loop (For Each) that iterate over the list of given builds and invoke each one, note here that I check if we want run the build in sequence, see the next step.

Run other workflow TFSBuild for each build definitions

If we want to run the build in a sequence (the condition is true) to make each build depend on the previous build's status and if one build fails then the main build will stop and fail.

To do so, I waited for the build untill it was finished and changed the main build status (success or fail). If it failed then the main build would stop (ThrowOnError) and fail, if it succeeded, it would go to the next iteration in the loop (wait for the next build).
Run build in sequence wait for build and set build status

If we don’t want to run the build in sequence (condition is false) we just need to trigger all builds with no dependencies, that means the main build always succeeds even if other child builds fail, because it doesn't depend on them. Even the main build may finish while other build still running. I made the main build wait for the last triggered build in the loop, but if the last build finished before the previous one, the main build will finish before all builds finish. So, I also changed (ThrowOnError) to be false.

Wait for the last build and success the build whenever

The DevOps zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

devops,tfs,team foundation server,build,automation

Published at DZone with permission of Mohamed Radwan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}