This document, together with the hello-world plugin, shows you how to get started with the plugin development.
What Can Plugins Do?
Hudson defines extensibility points, which are interfaces or abstract classes that model an aspect of a build system. Those interfaces define contracts of what need to be implemented, and Hudson allows plugins to contribute those implementations. See this document for more about extension points.
In this document, we'll be implementing a Builder that says hello. (built-in builders include Ant, Maven, and shell script. Builders build a project.)
Besides this tutorial, there are other tutorials and examples available on line:
- Stephen Connolly's 7 part tutorial (Writing a Hudson plugin)
- Part 1 - Preparation
- Part 2 - Understanding m2 and freestyle projects
- Part 3 - Subcontracting for Publisher and MavenReporter
- Part 4 - Abstract Publishers and MavenReporters
- Part 5 - Reporting
- Part 5½ - Typos corrected
- Part 6 - Parsing the results
- Part 7 - Putting it all together
- yet not finished: health reports
- Quick start guide in Japanese
Setting Up Environment
To develop a plugin, you need Maven 2 (why?) and JDK 6.0 or later. If this is the first time you use Maven, make sure Maven can download stuff over the internet.
With a fairly recent version of Maven (ie. 2.0.9 or newer) you should only need to add the following to your
~/.m2/settings.xml (Windows users will find them in
This will let you use short names of Hudson Maven plugins (ie. hpi:create instead of org.jvnet.hudson.tools:maven-hpi-plugin:1.23:create).
If you are using Maven version earlier than 2.0.9, you'll need to follow additional steps.
Creating a New Plugin
To start a new plugin, run the following maven command:
This will ask you a few question, like the groupId (the maven jargon for the package name) and the artifactId (the maven jargon for your project name), then create a skeleton plugin from which you can start with. Make sure you can build this:
-cpu means that Maven should update all relevant Maven plugins.
hpi: as prefix specifies that the following goal will invoke the part of the Hudson HPI Plugin, a plugin for supporting plugin development
create is the goal which creates the directory layout and the pom for the new Hudson plugin and it adds it to the module list
package is a standard goal which compiles all sources, runs the tests and creates a package - overwritten by the HPI plugin it will create a *.hpi file
Building a Plugin
To build a plugin, run "mvn install". This will create ./target/plugin.hpi that you can deploy to Hudson.
Setting up a productive environment with your IDE
NetBeans users can use the IDE's Maven support to open the project directly. (Bundled in 6.7 and up; available from Plugin Manager for 6.5.) The archetype may also be available right from the New Project dialog.
IntelliJ 7.0 (or later) users can load pom.xml directly from IDE, and you should see all the source code of libraries and Hudson core all the way to the bottom.
IntelliJ Maven defaults to downloading sources and JavaDocs on demand. So, to see the source, you may need to click the
Download artifacts button in the
Maven Projects tab.
Use Eclipse 3.3 or later to avoid a bug in Eclipse 3.2 (more details.)
Eclipse users can run the following Maven command to generate Eclipse project files (the custom outputDirectory parameter is used to work around the lack of JSR-269 annotation processor support in Eclipse:)
Alternatively, Eclipse users can install the maven2 eclipse plug-in, to open a Maven project directly in IDE.
If you get the error message Unable to find a plugin class. Did you put @plugin in javadoc? this maybe caused by eclipse and maven both use the target folder for build output.
Run mvn clean before building with maven or change the output path.
Plugin Workspace Layout
The plugin workspace consists of the following major pieces:
Maven uses it for building your plugin
Java source files of the plugin
Jelly/Groovy views of the plugin. See this document for more about it.
Static resources of the plugin, such as images and HTML files.
Let's take a look at the source code. A plugin's main entry point is a PluginImpl class that extends from Plugin. Once Hudson detects your plugin class (via its inheritance relationship from
Plugin), it will create an instance, and invokes methods.
Most of the time, a plugin class just registers extension points, and your main work involves in implementing those extension points. See the source code for more about how a
Builder is implemented and what it does.
Debugging a Plugin
NetBeans 6.7+ users can just hit Debug. For all others, run the following command to launch Hudson with your plugin:
If you open
http://localhost:8080/ in your browser, you should see the Hudson page running in Jetty. The
MAVEN_OPTS portion launches this whole thing with the debugger port 8000, so you should be able to start a debug session to this port from your IDE.
Once this starts running, keep it running. Jetty will pick up all the changes automatically.
- When you make changes to view files in
src/main/resourcesor resource files in
src/main/webapp, just hit F5 in your browser to see the changes.
- When you change Java source files. Compile them in your IDE (NetBeans 6.7+: Debug > Apply Code Changes) and Jetty should automatically redeploy Hudson to pick up those changes. There is no need to run
MAVEN_OPTS can be used to specify all sorts of other JVM parameters, like
If you need to launch the Hudson on a different port than 8080, set the port through the system property
Distributing a Plugin
To create a distribution image of your plugin, run the following Maven goal:
This should create
target/*.hpi file. Other users can use Hudson's web UI to upload this plugin to Hudson (or place it in
Hosting a Plugin on java.net
If you got to this point, you should definitely consider hosting your plugin on java.net. Move on to this document for how to do that.
Using custom builds of plugins included in the Hudson WAR
If you are building a patched version of one of the plugins in the hudson core, the deployment process is a bit different. This is because Hudson will itself manage these plugins unless you tell it not to.
Deploying a custom build of a core plugin
- Stop Hudson
- Copy the custom HPI file to $HUDSON_HOME/plugins
- Remove the previously expanded plugin directory
- Create an empty file called <plugin>.hpi.pinned - e.g. maven-plugin.hpi.pinned
- Start Hudson
- Consider running Maven like
mvn -o ...to avoid hitting repositories every time. This will make various operations considerably faster.
- Subscribe to the users' alias from here so that we can get in touch with you.
- When you bump up the version of Hudson you depend on, make sure to run
mvn cleanonce, in particular to delete
target/workthat Jetty uses. Newer versions may just use work, not target/work. Otherwise your Jetty may continue to pick up old left-over jar files.