Wednesday, June 2, 2010

Setting up Hudson on Ubuntu

Basic setup


First install the Hudson package, as explained in these instructions:

wget -O /tmp/key http://hudson-ci.org/debian/hudson-ci.org.key
sudo apt-key add /tmp/key
wget -O /tmp/hudson.deb http://hudson-ci.org/latest/debian/hudson.deb
sudo apt-get install daemon gij-4.3 openjdk-6-jre
sudo dpkg --install /tmp/hudson.deb

If all went well, Hudson is now accessible at http://localhost:8080/.

The next thing to do is to install a plugin for your favorite SCM. I use git so I went to Manage Hudson > Manage plugins and installed Hudson GIT plugin. Also install the Chuck Norris plugin for extra control.

You can now create a new job for your project. For this example I will setup a Python project that uses nose for its tests.

Go to New job, give it a name and select Build a free-style software project.

In the job settings, select GIT and enter the (read-only) URL of your project. You can check Poll SCM to trigger builds when the repository is updated, in that case you must define the poll frequency in the schedule text area, e.g. "* * * * *" to poll every minute.

Click the Add build step button, choose Execute shell and make it launch nosetests:

nosetests --with-xunit --verbose

Finally, check the Publish JUnit test result report option, and type **/nosetests.xml in there.

And you're done ! You can now start a build and check that it works fine. If it fails, look at the build's console output for details.

Advanced: setting up a VNC server for tests that require a display


Some tests, like the ones using the QtTest module, need a display connection to work and will fail:

cannot connect to X server :0.0

Hudson runs as a daemon and doesn't have access to a physical display, so we need to fake one.

Fortunately there is a plugin handling that problem in Hudson. Go to the plugins installation page and install the Hudson Xvnc plugin. You also need to install a VNC server on your machine. I chose to use tightvnc:

sudo apt-get install tightvncserver

Go to the Hudson configuration page (Manage Hudson > Configure system) and enter this command line in the Xvnc section:

/usr/bin/Xvnc :$DISPLAY_NUMBER

Return to your job's configuration and check the Run Xvnc during build option. Your tests will use the VNC server for their display, and should hopefully pass.

No comments:

Post a Comment