Hudson is a tremendously popular open source Continuous Integration tool mainly used for Java based projects. There is evidence that the Delphi community is picking up Hudson as a build tool as well (Hudson is built in Java) and even rumblings about Embarcadero themselves using Hudson to build Delphi.
I started using Hudson about a year ago in my day job as a step in organizing the build process for a bunch of Java projects that didn’t have an automated build and I have found it to be a tremendous help, not only in coordinating a team effort but also on a personal software process level, i.e. even if you are a single programmer on a project, I can guarantee you that you will see the benefit of using a CI tool like Hudson.
As I was getting totally smitten by Hudson in my day job, my hobby project in Delphi was suffering. Even though I was using Subversion and had automated build scripts and being a single developer I still found (my own) release process to be ad-hoc and brittle. So, enter Hudson to build my Delphi project as well. Since I am hoping that increased usage of Hudson in the Delphi community might lead to some new cool Delphi specific plugins from the Delphi community, I decided to write this little introduction.
Building a Delphi project using Hudson
Are there any prerequisites to start using Hudson? Virtually none – as you will see later on in this post, if you can write a few lines of batch script you are good to go. Well, maybe we should say that it is a pre-requisite to use one of the supported source code management systems(SCM). If your SCM is not supported, chances are you should switch (yes, it cannot be a popular SCM you are using…).
The first step is installing Hudson on a machine (if you have no other machine, your development machine will work fine). We shall not spend any words describing that since installing Hudson is so easy it should be set as an example for other systems!
The second step is to create what is called a job in Hudson parlance. A job can be described as the “build project” that describes all the aspects of building something. You will want to choose ” Build a free-style software project”
The third step is to link the job to your Source Code Management system. Out of the box, CVS and Subversion are supported, for all others, you need to first install the appropriate SCM plugin. Hudson will place all the files from the SCM in to a “Workspace” in the filesystem from where the project is built.
The fourth step is to add a build step. Select “Execute Windows Batch Command” in the drop down box. If you haven’t already created a batch file that can build your project, now is the time. Delphi is using MSBuild, which makes it quite easy to create such a batch file. Chances are it will be this simple:
echo Building My Delphi Project
call "C:\Program Files (x86)\Embarcadero\RAD Studio\7.0\bin\rsvars.bat"
msbuild /p:Win32LibraryPath="$(BDS)\lib;$(BDSUSERDIR)\Imports;$(BDS)\Imports;$(BDSCOMMONDIR)\Dcp;$(BDS)\include;" /t:build /p:config=Debug /verbosity:detailed "MyDelphiProject.dproj"
if errorlevel 1 exit 1
Test your batch script from the command line. If it works, you are ready to call this batch file from Hudson. Remember to check it in so that Hudson can fetch it from the SCM!
Now press SAVE on the bottom of the page.
Now you are ready to build your project. Select “Build now” and see if you get a blue dot for your project. If you get a red dot, go to the console output for that build to find out what happened.
So what have we done so far? We have made sure that Hudson can; 1. Fetch the source from the SCM. 2. Build it successfully. Now we need to make sure we live up to the “C” in continuous integration. This is done by configuring the “Build triggers” for the job to poll the SCM for changes. I usually set it up to poll every 15 minutes, but YMMV.
That’s all folks! May you all be successful in using Hudson to build your Delphi projects!