Saturday, March 28, 2009

Hudson Plugin 1: Setting up the system

This is an updated version of the tutorial written by Stephen Connoly to write a Hudson plugin. The plugin I create here was done on Hudson ver. 1.293.

Hudson is a continuous build system that I've been using for the past several months. It's been very useful, but my needs require a customized plugin. Although I have some ideas on how to create a great plugin, let's start with the following goal in mind:
  • Add a Post-Build Action, which is persisted. Example: default JUnit plugin
  • Have a trend graph for the build and project results. See an example below.
The only prerequisites to start working on a Hudson plugin are Maven 2 and Java 1.5 (JavaSE) or later. Yes, you don't need to worry about downloading or install Hudson itself, as Maven takes care of downloading the Hudson version you're developing for. You can launch Hudson with your development code using Maven, what speeds up the development greatly.

So, to set up your system, do the following:
  • Install Java SDK 1.5 or later
    Add it to your path and set up JAVA_HOME environment variable
  • Install the latest version of Maven 2
    Add it to your path and set up MAVEN_HOME environment variable
  • Install your IDE (in this example, we will use Eclipse)
Let's configure Maven to find Hudson. To do it, let's edit Maven's configuration file:
  • Find Maven's configuration file depending on your environment:
    Unix: $HOME/.m2/settings.xml
    Windows: $HOME/.m2/settings.xml
  • Add the following to your file:
    <activeByDefault />
Time to create the plugin skeleton (with Maven in the path):
mvn hpi:create
Note that groupId is the equivalent of package name and artifactId is the equivalent of project name. We used "com.sacaluta" for groupId and "performance" for package name.

Let's update the Hudson version this plugin will be for. As of this writing, the version that is set up in the pom.xml file (inside the plugin directory) is 1.279. Let's change it to 1.293.
<!-- which version of Hudson is this plugin built against? -->
And now we use Maven to make a Eclipse project out of it to open in our IDE:
cd  (e.g. cd performance)
mvn -DdownloadSources=true eclipse:eclipse

Finally, let's learn how to run Hudson from the command-line with your plugin code.
mvn hpi:run
Once we are done with the plugin development, we can package and distribute your .hpi plugin. This is the command to do this:
mvn package
DO NOT run "mvn package" while developing the plugin. If you do it and then want to run "mvn hpi:run", make sure to run "mvn clean" before that.

In the next post, we will start creating the plugin classes.

This first part of the plugin creation was heavily inspired in the Hudson Plugin Tutorial.
Post a Comment