Ok, so you’ve decided that you want to use Hudson to build your Grails projects (or have read part 1 and want to use CodeNarc too).
If you don’t know where to start, you’ve come to the right place.
The basic steps (and we’ll go into more detail on each one) are:
1. Download Hudson
2. Run Hudson
3. Download Hudson plugins
4. Configure Hudson
5. Create a Hudson job
6. Watch the trends
This post will get you started and subsequent posts in the series will add even more power to your CI process.
Step 1 – Download Hudson
Debian/Ubuntu users can install Hudson using ‘apt-get install hudson‘ (but if you’re on stable, it isn’t the latest version).
Step 2 – Install/run Hudson
Before we dive into the installation, you’ll need some pre-requisites installed:
– Java JDK (6 is best)
– Grails (whichever version you’re using)
As previously mentioned, Hudson comes as a war file and so it can be deployed to a servlet container such as Tomcat. The Hudson war file also includes the lightweight Winstone servlet container so can be run using:
java -jar hudson.war
Note that Hudson uses ~/.hudson as a working directory by default.
Key folders are:
jobs - job configuration, the workspace and builds are stored here
plugins - plugin .hpi files are unpacked to directories beneath this
war - the Hudson war file is unpacked here
Step 3 – Download Hudson plugins
Go to the available tab, find & select Grails, click on the install button.
When the plugin has downloaded and installed, you will need to restart Hudson (you can use the button provided).
Note: you can also manually install downloaded/compiled Hudson plugin .hpi files into ~/.hudson/plugins
Step 4 – Configure Hudson
Now we need to set-up the JDK and Grails – so have their paths handy.
Click on the “Manage Hudson” menu item
Step 4.1 Set-up the JDK
- Give it a name
- Set the JAVA_HOME
Step 4.2 Set-up Grails
- Give it a name
- Set the GRAILS_HOME
Congratulations, you’re now ready to set-up your first Hudson job.
Step 5 – Create a Hudson job
If you have lots of Grails projects, you’ll only need to do this from scratch the first time as Hudson allows you to copy existing jobs.
- Enter a job name (Tip: Hudson will use this for a directory name – so be careful what characters you use)
- Select “Build a free-style software project”
- Click “Ok”
For the first pass at the configuration, let’s assume that you have a working copy of the code locally (you can always come back to set-up the Source Code Management settings).
You can now perform the basic configuration of the Grails step. Let’s set it to do a clean, followed by execution of the unit tests:
clean "test-app -unit"
Unless you’ve set up the SCM configuration, you’ll want to specify the root of the Grails application in the “Project Base Directory” too.
Finally, we want Hudson to publish the unit test results (this is relative to the workspace under ~/.hudson/job/Example/workspace).
If the working copy is clean, Hudson may complain that the XML results or the target directory do not exist – this can be safely ignored for now.
If the build passes, it will be marked as blue (this can be changed to green balls with a plugin).
If the build fails, then click on the failed job
and look at the error message under “Console Output”.
E.g. If you select Subversion as an SCM option, but leave the form blank:
Step 6 – Watch the trends
Assuming you’ve got it all working – after you’ve performed a few builds, Hudson will start to show build trends on the job page…
We’ll add more statistics to this view in later posts in the series.
It is advisable to pick a specific Grails installation rather than leaving ‘(Default)’.
Check your job configuration if you see errors such as:
FATAL: command execution failed
java.io.IOException: Cannot run program "grails" (in directory "/var/lib/jenkins/jobs/GGUG/workspace"): java.io.IOException: error=2, No such file or directory