Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Create One Main Build Process to Invoke Other Builds

DZone's Guide to

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
Free Resource

Learn more about how CareerBuilder was able to resolve customer issues 5x faster by using Scalyr, the fastest log management tool on the market. 

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

Find out more about how Scalyr built a proprietary database that does not use text indexing for their log management tool.

Topics:
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.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}