The Perfect Build Setup – Hudson


[tweetmeme source=”gosub3000”]

Introduction.

I have had a passing acquaintance with Hudson for some time, but it is only recently that I’ve had to get down and dirty with it.  For one reason or another, much of the build infrastructure work for my current project has fallen on me.  This has allowed me to become much more involved with Hudson on a daily basis, and I have to say I’m loving it.

Hudson is a continuous integration environment.  We have configured it to check code out of our subversion repository on a regular basis, run the build scripts, gather the cobertura code coverage, junit test reports, findbugs reports, etc., and have these metrics published and trended over time.  I think I can speak for my team when I say, we’ve found it a boon to be able to regularly build our system in a clean environment, and gain such insight into our code quality.

So without further ado, I present instructions to allow you to set your own build system up in 20 minutes or less.

Gather the bits.

I’m assuming you’re starting with a fairly blank operating system.  I have tested these instructions on Windows XP, but they should be applicable to any other OS also.  Following a similar process would work on Ubuntu, for example.

Hudson is shipped as a web application (war file), so you’re going to need a hosting environment.  I would suggest Jetty, as it’s easy to set up, and register as a windows service.

Since Jetty is java based, you’re going to need a Java Run-time Environment.  Depending on your use of Hudson, you may also need a Java Developer Kit.

The software I used was:

Installation Procedure.

To begin, install the JDK.  Typically I try to keep developer tools together, so I installed Java to c:\devtools\Java\, but any directory you choose will do. As always when installing Java, ensure you set the JAVA_HOME environment variable to where you have installed Java.

Next, install Jetty.  Jetty ships as a zip archive.  I recommend 7zip as an easy to use archive tool, if you don’t already have a favourite.  Once unzipped, copy (or move) the jetty-6.1.12 directory to c:\devtools\jetty-6.1.12\.

Unfortunately for our purposes, the Jetty zip archive includes everything short of the kitchen sink.  Under jetty-6.1.12 directory you’ll find Jetty source files, javadoc, and much much more.  When you’re up and running, you can come back and trim the fat, if you’re concerned about disk space.  See the Jetty docs for more information.

Jetty uses the Java Service Wrapper, allowing you to easily register your new Jetty install as a Windows service.  This allows you to control the Jetty instance through the Windows Control Panel Services applet.  This is worthwhile, as you can configure the service to start automatically when your server starts.

To register as a service, open a command prompt, and change directory to c:\devtools\jetty-6.1.12\bin.  Register the service by issuing the following command:

Jetty-Service.exe -i jetty-service.conf

By opening the services applet in control panel, you should see “Jetty6-Service” listed.  This is your new Jetty instance.

Now that Jetty is available, it’s time to install Hudson.  Since Hudson is going to be downloading source and building it, it’s going to need a place to work.  By default (in this setup), Husdon will use c:\.hudson\.  If you would prefer a different location, you can specify this by creating a HUDSON_HOME environment variable with the directory you desire.  I chose c:\devarea\hudson.

Deploying hudson is now as simple as copying (or moving) the hudson.war file to c:\devtools\jetty-6.1.12\webapps\, and starting (or restarting) your Jetty service.  Once this is done, you should be able to point your browser to http://localhost:8080/hudson/ and see the Hudson welcome page.

Configuring Hudson.

If you’ve made it this far, well done!  Now we need to configure Hudson for use.  This is accomplished by clicking the “Manage Hudson” link, followed by the “Configure System” link.  The following page is the main configuration page for Hudson.  In order to build a project, you need to tell Hudson where to find tools such as Java, Ant, cvs, subversion, etc.  I’ll leave this configuration to you, as each Hudson instance is set up to fulfil your own needs.

Once this is done, you can add jobs from the main page, and you’ll be building in no time.

Further Reading

Granted, this is a whirlwind tour of a Hudson setup.  If you need additional help, you can ask in the comments, or try these pages for more information:

Advertisements

Tags: , , , , , , ,

4 responses to “The Perfect Build Setup – Hudson”

  1. Curt Cox says :

    Actually, Hudson can act as it’s own servlet container. Just use java -jar hudson.war and your’re off.

  2. ccollins says :

    @Curt,
    While that is true, I would only consider that a demo mode of use. Once you log out, your JRE will stop, and you cannot connect to Hudson.

    We are planning on using Hudson over several months, so this is why I chose to deploy it to a more stable hosting environment.

    -Chris

  3. ccollins says :

    @Curt,
    Well, you learn something new every day. I’ve been using Hudson for a while, and I hadn’t noticed that this was an option.

    Thanks for pointing it out. It certainly seems more straightforward than my suggested approach.

    I’ll definitely be suggesting this approach, whenever someone asks how to set up Hudson.

%d bloggers like this: