Wednesday, October 17, 2007

A RoboCopy TeamBuild Custom Task

How Steve Got Burned Today - Frankenstein's Custom Task: A RoboCopy Custom Task for Team Build 

"I was recently working at a client on a TFS implementation.  They had been using TFS for a few months and had some cycles invested in their build process.  As part of the process, they  needed to deploy the compiled web sites out to a development test server so that they could review the code with their BAs prior to calling the Story complete.  They also had a requirement that they be able to have an indication that the deployment step was occurring during the build (in the Build Status page).

Their Team Build was constructed using the <Exec> task to call RoboCopy to do an "sync" between the drop folder and the deployment folder on the target web server.  Unfortunately, every time they ran this task the build broke.  It seems that RoboCopy doesn't follow the standard rules of command-line apps.  The standard rule is "Return code is 0 on success and anything else denotes an error condition". 

...

What's a consultant to do?  Why I Googled up "MSBuild RoboCopy" and was rewarded with a link to the MSBuild Community Tasks on Tigris.org.  Sweet!  I knew that they had code to do what I wanted, so I grabbed it from their repository (thanks guys).  This code is for a straight MSBuild task and therefore couldn't talk to Team Build (and by extension TFS). 

To get that functionality, I remembered an article by Aaron Hallberg entitled "Adding BuildSteps to Team Build Through a Custom Task."  I brought up the article and nabbed that code too.  I also had some code laying around from earlier custom tasks I wrote to wrap command-line tools since I needed to evaluate and correctly interpret RoboCopy Return Code. 

With all of this code in hand I went down to my mad-scientist lab to cobble together the Frankenstein's Monster of custom tasks, a RoboCopy task that will correctly evaluate the return   code and add a BuildStep to a Team Build. [Evil laugh here]

...

I've put links below to the solution and binaries.  This custom task could easily be updated to call any command-line tool while logging BuildSteps to the Team Build.  This task will only work under Team Build because it requires a BuildURI and TeamFoundationServerURL parameters but it could be easily modified to remove the Build Steps and work under MSBuild alone.

..."

I use RoboCopy all the time (and have for years) and I can see my wanting to use it in a TeamBuild scenario...

No comments:

Post a Comment

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...