Just like you should be using Source Control (even if you are a one man operation), you should be doing continuous integration. We currently use CruiseControl.net, but we are giving Hudson a look here at Gateway Ticketing, and it seems likely that we’ll end up switching and using it. So naturally, I decided to play around a bit with Hudson. We used Hudson quite extensively at Embarcadero, but I had never really given it a whirl myself.
This is the Hudson Dude whose picture shows up in the Hudson interface.
He’s quite dapper, no?
Hudson is Java-based, but don’t let that scare you. You need not know a lick of Java to use it effectively. It is very, very easy to download, install, and get up and running. I found this blog post helpful in that regard. I was up an running in minutes.
Hudson has a very nice browser interface for configuration. It also has a very large and growing collection of community of plug-ins. Hudson also makes it really easy to install plug-ins by providing support right in the interface. Add them isn’t much more than selecting them in a list an clicking install.
Plugins are important, because you are going to need them in order to do a Delphi build. The first one you’ll want to install is the MSBuild plug-in. This will allow you to choose MSBuild as a build environment.
All of the popular source control systems have plug-ins. I’ve been using Mercurial on my local machine, and so I chose that plug-in as well.
I also discovered, after a series of trial and errors that the setenv plug-in is pretty much required as well. As you may know, to do command line builds of Delphi projects, you need to set a number of environment variables. This is usually done via the rsvars.bat file. Well, Hudson doesn’t know about that at all, and I didn’t have much luck running it as a batch file before doing the build. Hudson seems to isolate the environment for each individual action. The setenv plug-in lets you set global and local environment variables for Hudson. Since I’ll be doing a lot of Delphi builds, I selected “Manage Hudson” and took the items from rsvars.bat and set them up as Global Properties:
Doing that is critical, as that sets everything up so that Hudson can find the files needed by every Delphi project to define the build targets. There are a couple of StackOverflow questions about this very topic that recommend passing a few parameters, but I found that if you set up setenv to incorporate what rsvars.bat does, you don’t need to pass any parameters on the MSBuild command line beyond the *.dproj or *.groupproj filename.
In addition, you need to tell Hudson about MSBuild specifically – that’s easily done in the global configuration as well. Basically you give each installation a name and the full path to the MSBuild.exe for that .net version. You might want to set up different MSBuild installations for the .NET 2.0 and .NET 4.0 versions, for instance.
Once all that is set up, it’s really a matter of setting pretty self-explanatory properties of Hudson.
- Select “New Job”.
- From here, I just chose “Build a free-style software project” to do a simple build of a Delphi project group.
- Give your job a name and click Ok.
- From there, you can pretty much figure things out. I did the following.
- Pointed Hudson to the Mercurial repository I wanted it to pull from, including the branch I wanted. The settings for Subversion and other SCM systems may have different settings.
- I chose to poll Mercurial for changes. The “code” for setting that up is a bit tricky, but I found pressing the help button gave a pretty good rundown and some examples. I just set it to poll every minute. Not a big deal on my local machine, and it makes it easier to see how things are working while testing it out.
- The final thing to do was to actually tell Hudson what to build. That was easy – I have a project group called
and I simply added that as the MSBuild build file after telling Hudson which version of MSBuild to use.
And that is pretty much it. From there, you can tell Hudson to build for you on demand, or you can just leave it to run, and it will build everytime it sees a change in your source. Again, the “tricky” part was getting and using that setenv plug-in. That simplified everything.
UPDATE: Christer Fahlgren has also written a very nice blog post about running Hudson on Delphi projects.