Get latest buildable code
December 18, 2007 – 3:09 pmOne of the headaches with getting latest version from source control is of course breaking the state of your local build. The unfortunate fact is that often in development teams, developers checking in code end up breaking the build, either by multiple developers checking in incompatible code or by not checking in all files necessary. I do understand it, of course. It has happened to me too, and it probably will happen again. After all, it works on my machine, right?
There are numerous ways to prevent this, however. At our R&D, we are ~20 devs using Team Foundation Server and CruiseControl.NET for continuous integration, meaning every time anyone checks in anything, a build is triggered on one of the CI servers (each team/branch has own). CCtray, a tiny system tray app lets us know the state of the build for our branch, and unless the icon is green, it is either building (orange) or failed (red) and that is usually a bad time for “Get Latest”. This is no news for many, but I felt I needed to describe it nevertheless.
Despite this safety net, the reality is that CI server build is often broken or building with uncertain outcome. Getting latest with build server in those states can result in broken code so one has to look out for green light from CCtray before getting latest, both tasks easily forgotten or delayed. This annoyed me so I decided to write (I boldly assumed there wasn’t one just like it written already) a small console app that automates this process:
- connect to a CruiseControl.NET server via remoting and get status for specified project
- if project has built ok, perform get latest from TFS, if building or broken, do nothing
Values that need to be specified are server name, project name and local working folder.
While writing this post, another issue came up: Working in offline mode. This turned out to be somewhat tedious in terms of editing files in disconnected mode from TFS and letting TFS know to pend those changes next time you come online. Best way we know about was TFS power tool command “tfpt online”, but running that command from root node of one of our branches was often equivalent of pulling the plug out of the wall. As we’re talking in the vicinity of 30.000 files in the branch, the load just got too heavy. To prevent this, one would have to keep track of the folders where changes were being made and execute the “online” command specifying only those folders, but that was bound to result in something being left out as it demands strict manual control on every part.
Command tool utility to the rescue again, and since I had one already, I thought the best way was to combine it all in a same app. So I added another switch that says to the app to iterate the specified working folder for all project files and parse them to retrieve all source code files in them. Folders that contain writable files (meaning something is up) get logged and “TFPT online” command is run only on those folders, so to prevent the server getting blasted by the workload of executing on the root level.
So, now I ended up in a two-fold purpose built command-line tool that anyone is welcome to get. It has a number of switches, but they basically group in two operation types:
- Integration with CruiseControl.NET
- Automating “tfpt online” command from TFS power tools
usage: tfssync [[/s:servername] [/p:projectname] [/cc]] [/online [/filemask] [/preview]] [/wf:workingfolder] [/uu] [/log:logfile] [/verbose] /s CCnet Server name /p CCnet project name /wf Your local working folder /uu Perform TFPT undo of unchanged files before get latest /log Log output to file /cc Check status of CruiseControl.NET without taking further action /online Search for writable project files and perform TFPT ONLINE on containing folders /filemask Filemask for searching for writable files (semicolon delimited, example: "*.cs;*.csproj;*.sln" /preview Adds /preview switch to TFPT ONLINE (no action performed) /verbose Outputs more detailed information example (CCnet): tfssync /s:172.120.120.120 /p:"Build team 1" /wf:c:\dev\code /log:output.log example (TFPT ONLINE): tfssync /wf:c:\dev\code /filemask:*.cs;*.csproj;*.sln /preview
TFS Command line integration tool
PS. Realize there are a few prerequisites:
- Integration with CruiseControl.NET will require DLLs from ThoughtWorks (ThoughtWorks.CruiseControl.Remote.dll, ThoughtWorks.CruiseControl.CCTrayLib.dll). If you have CCtray installed, they are already in the \Program Files\CCTray folder.
- Running the TFPT commands obviously requires TFS power tools (available free at MSDN)
del.icio.us