Hudson – A Getting Started Post

Hudson – why?

3 reasons really.

Firstly I’ve been working my way through my backlog of marked Google Reader articles to read. One of them was The Guerilla Agile Series (link to post 6, which contains links to the previous articles). Its a good series and it sparked me into life. In the linked article it contains a post to Hudson, something I’d not heard of before but thought, hey I’ll give that a go.

A second reason is currently one project is not in a buildable state. I would be nice to have notification of that as early as possible – functionality that Hudson provides.

Thirdly, upon changes jobs I decided I really would become Agile. I’d experiemented quite a lot in my previous role, focusing especially on Test Driven Development. I’ve not applied it as much here, but now I’ve been here 6 months I guess its time to! I’ve got a natural break coming up in a couple of weeks and when I return thats when I’ll really go for it. From now until then though I’m going to do as much experimenting as possible with different technologies to help facilitate that changes – and the Guerilla series has certainly been an excellent resource.

Hudson – Getting Started

First off – ground rules as per usual – I’m on a Windows XP machine. I’m going to use Tomcat to host Hudson (and its already installed and working).

Tomcat Configuration

I changed the default port for Tomcat from 8080 to 8081 (in the conf/server.xml file). This was solely because I’m using GlassFish locally for a lot of development work and its configured to run under NetBeans under port 8080 – I didn’t want to risk any conflicts.

I also set the Tomcat Windows Service to start automatically (I’d forgotten I’d installed Tomcat, and when I had I’d obviously perceived I wouldn’t be using it much so it was set to manual start-up).

Hudson WAR Download & Installation

I grabbed the Hudson WAR download for Hudson.

I then fired up my browser and pointed to localhost:8081 to get the Apache test page to come up. In the top left corner is a link to Tomcat Manager and I went in there (after it prompted me for username and password, which I found in my tomcat-users.xml file under Tomcat 6.0\conf).

I then selected the Deploy WAR option, specifying the downloaded file.

Pointing my browser to http://localhost:8081/hudson I got the Hudson page!

The Project & Ant

So before creating a Hudson job to monitor a project, I evidently needed a project to monitor. Firing up NetBeans and creating a simple HelloWorld java application, I created an SVN repository to store this initial project into.

To save sometime later, I also found (much later!) that I didn’t have ant installed on my machine – I had a copy bundled with NetBeans, but Hudson required a local copy. So I downloaded the ant program from Apache Ant. I installed to ‘C:\apache-ant-1.8.1\’ directory.

I then spent a while playing around with the Path variables in Windows get ant.bat recognisable from anywhere. I ended up having to do a system restart for Windows to pick up the new settings.

Hudson – First Test Job

Back in Hudson, click ‘New Job’.

I gave this job a title of ‘TestSVNCommitNotification’ and selected ‘Build a free-style software project’.

On the next page I set the following:

Source Code Management System

Selected Subversion and supplied the file:/// protocol path to my local repository.

Build Triggers

Select Poll SCM and set the schedule to a sign line of 5 ‘*’ seperated by spaces, e.g.

* * * * *

Build

I selected Invoke Ant and entered a target of ‘default’.

I also need to specify the path to the build script under Advanced ‘HelloWorld/build.xml’ due to the way NetBeans sets up the projects.

This set-up my job and so I saved it.

I then clicked the Build button to try an immediate build. The build failed and checking the Console Output the error was in the test section of the build.xml – the error message given was:

Error msg of : The <classpath> for <junit> must include junit.jar if not in Ant’s own classpath

I searched for junit.jar on my local system and copied this file into the Apache Ant \lib directory.

I then tried the build again and got a success message. Checking the Console Output I could see that the project appeared to have built.

I also played around with a couple of code changes and commits, and each time Hudson detected the SVN had been updated and built the new project (or failed if I introduced a compiler error).

Configuring Email Notification

The main reason for deploying Hudson (for me!) though is to get email notifications of failing builds. For this I needed to use my Google account.

So in Hudson, I selected Dashbord->Manage Hudson->Configure System and then scrolled to the Email Notification Section.

I then set the following settings:

SMTP Server : smtp.gmail.com

Then clicking the advanced button and set the following:

Username : <<enter your Google Email Address >>
Password: <<enter your Google Email Password >>
Use SSL: Checked
SMTP Port: 465
I left the charset set to ‘utf-8’.

I then headed back to the job I had created and checked the Email Notification under the Post-Build Actions section. I then entered the email address I wanted email notifications to go to.

I then did a couple of failing commits, seeing that I received the email notification. Fixing the compiler issues resulted in receving a success email notification to say the problem had been fixed.

Where Next

I need to integrate this with a real life Java project, which doesn’t seem like it’ll be too much trouble, and then with a real-life .NET project which may be interesting. If I have any findings (and hopefully I won’t!) I post a new blog post with these findings.

Oh, I also need to send a quick thank you to the author of the Guerilla series posts.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s