Introduction
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily – leading to multiple integrations per day.
- Martin Fowler
Hudson is a popular open-source continuous integration server used by many organizations like Redhat JBoss. Though there are many well known and well established open-source projects like CruiseControl, Continnum and some commercial offerings like Bamboo, what makes Hudson special is it’s powerful yet easy to use web interface, it’s simplicity and it’s extensible architecture with many plugins.
Objective
The objective of this tutorial is to setup, configure and learn to use Hudson by building “Apache Commons IO“, a well known java project.
Requirements
- Hudson
- Subversion (or any other version control system like CVS, Mercurial, Git if you want to build your own project)
- (Optional) Tomcat or Glassfish
- Apache Ant (or Maven)
Installation and Starting Hudson
Installing Hudson is super easy. Just download the war file, open your terminal/command-prompt and issue the command “java -jar hudson.war”. Now point your browser to http://localhost:8080. That was easy, right?
Hudson has an embedded servlet container called “Winstone” which works much like a standard servlet container like Tomcat by serving your JSP pages and servlets.
If you want Hudson to start on a different port, say 8180, issue the following command,
<code> java -jar hudson.war –httpPort=8180 </code>
Ofcourse you can deploy Hudson to Tomcat, Glassfish or any other supported servlet containers. The following guides can be useful in that case:
More container specific guides can be found from this hudson wiki.
Once you started Hudson or deployed it to a servlet container, this is what you might see in your browser when you start Hudson for the first time.

Hudson Home Directory
All your Hudson jobs/settings are stored in the Hudson home directory. If you did not specify one, Hudson shall assume some defaults like <code> ~/.hudson </code> in Linux or your respective home directory in Windows. It’s ok to go ahead with the defaults while you test drive Hudson but once you are done, I strongly recommend you to define a Hudson home directory of your choice, preferrably on a separate partition or drive. This will ensure that all your Hudson configuration/jobs are intact in case of any system crash.
Say, suppose your home directory is “/hudson” (in Linux), this is how you will define the Hudson home directory,
If you are using the embedded servlet container, start it by specifying the java system property “HUDSON_HOME”,
<code> java -DHUDSON_HOME=/hudson -jar hudson.war </code>
If you are using Tomcat, follow the explanations in this wiki. However, if you run Tomcat as a windows service, you need to do some tweaking to let Tomcat set this property. In that case, you will be better off if you start Tomcat using it’s batch file and set the property right there. (Or if you managed to run Tomcat as a Windows Service and still able to define the Hudson home correctly, why don’t you share your views with us?)
If you are using Glassfish, go to admin console and add the JVM option <code> -DHUDSON_HOME=/hudson</code>. More detailed explanations can be found on this wiki.
Just remember that the idea is to define a system property “HUDSON_HOME” through any of the possible ways.
This is how the Hudson home directory shall look like.

Manage Hudson
Hudson provides an easy to use web interface to manage the configurations needed to administer a continuous integration server. Let us do some basic configurations to get Hudson ready.
Start Hudson and click the “Manage Hudson” link located on the left.

Now click “Configure System”. Hudson will display a page where you can configure things like access control, JDK, Ant, Email Settings etc.

Access Control
We will enable security to secure our Hudson setup. Otherwise anybody can go and meddle with your Hudson jobs. If you don’t want that to happen, check the “Enable Security” checkbox.

Once security is enabled, we need to tell Hudson the type of “Access Control” we want to use. Let us choose the Security Realm as “Hudson’s own user database” and leave the option “Enable users to signup” as checked. (If you do not check the “sign up” option here, Hudson is definitely going to whack you later!. ) Under the “Authorization” section, choose “Matrix-based Security”.

Now add an user called “administrator” and give the necessary privileges. ENSURE THAT YOU GIVE “ADMINISTER” PRIVILEGES TO THIS USER or else, you may not able to access the administrative console once security and access control are enabled. (Again, if you miss it, Hudson is gonna whack you!)

Hudson will display an error symbol near the user we just added. That’s because the user does not exist in the system. Do not bother, we will create the user a little later. Now go ahead and add users who might be accessing Hudson. Give appropriate access controls to the users and do not give full access to everyone. That will eventually create a system that is difficult to manage.

Configure JDK
Done with security? Now we need to configure the JDK which Hudson shall use to build the jobs. Find out the section “JDK” in the same page. Click the “Add JDK” button and then enter the details of your JDK.

Configure Ant
We need to tell Hudson where Ant is located. Find out the section called “Ant”, click “Add Ant” and enter the respective details.

(Follow the same procedure, if you want to configure Maven.)
That’s it! Hudson is now almost ready for prime time. Feel free to configure the Email Settings as well with the appropriate values. When you are done, press the “Save” button to save all the changes you have made.
Once you press the “Save” button, Hudson will redirect you to a login page.
Manage Users
Click the “Signup” link at the top right corner of Hudson and register a new user called “administrator” (or whatever name you gave in the “Access Control” section).

Hudson will automatically login the user provided the user was already configured in the “Access Control” section. Once a new user (administrator) is registered in the system, Hudson will provide an option called “Manage Users” in the “Manage Hudson” page.

You can now create other users from this page.

You will be using this page to manage all your Hudson users. Looks like we have covered quite a lot of information. It’s time now to create some jobs and see Hudson in action.
Creating Job
That’s the core feature of Hudson. Hudson jobs can fetch the source code from a repository, execute your build scripts, run your tests, prepare javadoc, notify you in case of any failure, archive the build artifacts and much more. That’s where you can really see the power of Hudson. Enough talking, let us explore these Hudson features now by creating a job.
The Hudson job which we are going to create now is going to be very simple and is capable of doing the following:
- Checkout the source code of apache commons-io project using subversion
- Run the build script (build.xml in case of Ant, pom.xml for Maven)
- Archive the build output
Create a job by clicking the link “New Job” on the left. Give a name for the job, select the option “Build a free-style software project” and then press “OK”.

Configure Job
Hudson will create a new empty job for us which we need to configure.

Let us configure the repository for this job first. Go to the section “Source Code Management”, choose the option “Subversion” and enter the repository url as “http://svn.apache.org/repos/asf/commons/proper/io/trunk“. Enter the “Local module directory” as “.”

Look for the section called “Build”. Click the button “Add build step” and select “Invoke Ant”. Leave the rest to default. (Maven users, choose the appropriate action)


Go to the section “Post-build Actions”. Select the checkbox “Archive the artifacts”. The apache commons-io build script shall create the jar in the directory named “target”. So enter the value “target/*.jar” in the text field titled “Files to archive”. Though this is not mandatory to build a job, I recommend you to do this as this will help the users of your continuous integration server to download the build outputs quickly.

NOTE: Since we are building the apache-commons-io project we are entering the value “target/*.jar”. If for example, your build output directory is “dist”, then you should enter here as “dist/*.jar”.
Press the “Save” button at the bottom. Our job is ready and just click link “Build Now” at the left to start building the job.

Once the build is initiated, you can relax and watch the progress in the “Build History”.

If you are restless and want to see exactly what is going on, just click the link (corresponding to the build number) in the “Build History”.

Now click the link “Console Output”.

Hudson will display you the console view where you can do all your research.

Now that the build is successful, you might want to have a look at the jar built by this job. You can find that under “Last Successful Artifacts”.

You can also have a sneak preview about the builds from your Hudson home page.

If in case some of your builds failed, Hudson will report that as well neatly along with displaying the build stability.

That’s it for now. But you can do a lot more like configuring Hudson to build this job every few minutes or just poll the repository once in a while and trigger the build whenever someone commits to the repository. Explore them under the job’s configuration page and enjoy. And did I mention that Hudson has a lot of good plugins already? Maybe I will try to cover those advanced concepts in my next post.
If you are using NetBeans as your IDE, then you have a got a lot of Hudson features integrated right into the NetBeans IDE. Check that out in my post NetBeans 6.7 – A quick glance.
Are you using Hudson? Are you planning to use Hudson? Why not leave a comment below and share your thoughts?
Read also: “NetBeans and Maven – A quick start guide”



[...] more about Hudson from the blog post Hudson CI Server – A step by step guide – Part I. Share and [...]
[...] New Hudson articles: Intro@SolitaryGeek and at [...]
Note that any user seems to be able to access the ‘people’ page and view ALL the users in the system, Hudson’s security seems to be a little lax in this area.
Hi there,
Interesting, I`ll quote it on my site later.
Have a nice day
Hi, Interesting, I`ll quote it on my site later.
Thank you
Hudson is a slick tool, but I won’t be recommending it to anybody any time soon. If you can actually even manage to download it you’re lucky, since the website seems to have about 10 minutes uptime a week. This is frustrating when something goes wrong, and you can’t even get to the friggin’ documentation. My install just started refusing to deploy anything to my Maven repo, it just claims the credentials don’t work, but Maven itself has no problem using the same credentials. Since I can’t find out ANYTHING about this problem it’s back to bloody CruiseControl for me. At least it works, and there’s reliable documentation about.
Hi I have a problem with the connection to Subversion. When I entered the Repositoy URL ““http://svn.apache.org/repos/asf/commons/proper/io/trunk” Hudson displayt me
“Unable to access http://svn.apache.org/repos/asf/commons/proper/io/trunk : svn: OPTIONS of ‘/repos/asf/commons/proper/io/trunk’: 501 Not Implemented (http://svn.apache.org)
svn: OPTIONS request failed on ‘/repos/asf/commons/proper/io/trunk’ (show details)
(Maybe you need to enter credential?)”
Please help me.
I want to create source code repository and have to include android/iPhone project..
How to include a build in Hudson server?
how to create source code repository ?
How to use Hudson from my iPhone or iPod ?
@Luke Well, for the iPhone and iPod i discovered an app on the App store that is called HudsonMobi (www.hudson-mobi.com)
I think it is the the only one suitable application to connect to any instance of Hudson server, you can do almost anything in the fastest way. I suggest you try this app.
Unfortunately this does not work. This is my first encounter with Hudson,as everyone raves about it, but I am distinctly unimpressed. As soon as you try and activate the security and create a user, and hit save, it asks for a username and password. Which you haven’t had a chance to give it yet. So you can’t login or create a user or do anything. So you have to delete the config and start again. I don’t know whether to give up now. if an application can’t even get user management and security right, what it is going to be like for more complex operations?
How can I build a java project with hudson?.. I am not getting where I can specify list of lib jars.
[...] this first create a new job in Hudson. This link will help you understanding the Hudson management; http://www.solitarygeek.com/java/hudson-ci-server-a-step-by-step-guide-part-i/ After creating a job, go to configure section of the job and “Add build step” to run shell [...]
Thanks for this great article, James. Terrific presentation. Much help for a first-time Hudson install.
Great. This article help me a lot!
Hi,
Very usefull document for a person who is a new-bee in hudson. I am able to learn about hudson build process because of this useful info. Thanks for this documentation that too with snapshots and description.
Thanks a lot again.
chandru
Simple and working guide i came across. Thanks
Great post guys, I have been using Hudson for a couple years now and would never look back. We have configured Hudson along with Apache Ivy to provide an all round Continuous Integration and Dependency Management System for our Software Project. Check out my post titled “Hudson and Ivy together conquer Continuous Integration and Dependency Management” on my Blog site at Tecuterology
Hi,
quite interesting and good for beginners.
To set Hudson home when using Tomcat as a service (on Windows XP anyway).
From Start -> All Programs -> Apache Tomcat 7.0 -> Monitor Tomcat, OR Configure Tomcat.
If using Monitor Tomcat, when the icon appears in the tray in the lower right hand corner, select Configure.
Select the Java tab, then in the Java Options box add : -DHUDSON_HOME=D:\Tomcat 7.0\hudson
I found this article really really useful : hope this little contribution helps someone else.
Hi James
It was a wonderful and informative page for me… I was struggling hard with hudson management and I got a lot of valuable info from this page…
Thanks a lot..
Sriti
[...] Hudson CI Server – A quick start guide " SolitaryGeek (tags: ContinuousIntegration java hudson) [...]
[...] java.net/projects/hudson-plugins java-source.net/open-source/build-systems/hudson solitarygeek.com/java/hudson-ci-server-a-step-by-step-guide-part-i blog.jepamedia.org/2009/10/28/continuous-integration-for-php-with-hudson/ [...]
[...] and Welcome to LinuxQuestions, Have a look at this page, it has a step by step guide for beginners. I don't use Tomcat for Hudson, instead I just use a [...]
This is a GREAT resource! Thanks so much for helping me get started with Hudson – everything worked correctly the very first time I tried it.
Cheers,
–>S.