Skip to main content

Kickass Hudson Plugins - part 1 - Setenv and the Description Setter

Posted by johnsmart on October 6, 2009 at 8:51 PM PDT

One of the awesome things about Hudson is the sheer number of plugins available. In fact, if you use Hudson, make a habit of checking out the list of available plugins every month or so - there's bound to be something new that you could use! In this article, I explore two relatively new ones: the Setenv plugin and the Description Setter plugin.

The Setenv plugin

Many build scripts use environment variables for a variety of purposes, particularly legacy, Ant-based ones. Some use them to determine the server the build is running on, the target environment, or where certain tools are installed. Still others use shell scripts to do a variety of initial work before the Ant or Maven kick off. This may or may not be a good build scripting practice, but when you are migrating projects onto Hudson, you may well find yourself needing to make it work.

This is actually quite tricky to do in Hudson. You can set environment variables that apply across all projects, but this is a little heavy-handed. You can pass properties into Ant and Maven build jobs, but not to shell scripts. You can use an Ant script to bootstrap the environment by initializing environment variables, and then invoking the shell script, but this is hardly an elegant solution. However, you can now do this with the Setenv plugin. This plugin lets you define environment properties on a per-project basis, and works fine with any kind of build job:

 

The Description Setter plugin

Have you ever wondered what version of your application was built by a particular build? Or what build was responsible for a particular version? Sure, you can go into the log files, but this is not exactly a user-friendly solution. The Description Setter plugin now lets you do something much nicer.

This plugin lets you extract a text from the output of your build jobs, using a regular expression, and assign that text automatically to the build job description. The trick is to identify the label you want to extract from your build output, and find a regular expression that will isolate it. For example, if you are using the Maven Release plugin, your build output will contain a line like the following:

... [INFO] Uploading project information for killer-app 1.2.3 ...

With the Descriptor Setting plugin, you can set up a regular expression like the following to isolate the build number. You can put use multiple regular expressions, just remember to enclose the one you want to use as a label in parentheses, as shown here:

Once you have done this, your builds will automatically be labelled with the text extracted from the build output:

And, if there where any doubts that Hudson plugin developers have a sense of humor, check out the Chuck Norris plugin. This lets you add an appropriately grim or cheerful picture of Chuck Norris to your build jobs, along with a Chuck Norris programming quote.

"Probably the best training course I've been on."..."Not just how to write Java code but the 'business end' - how to build, test, deploy, manage and monitor"..."One of the best and most useful courses I have attended. And they didn't even try to sell me anything!" - Hurry! Sessions coming up very soon in Sydney and Wellington - Get up to speed with the latest and coolest in Java tools and best practices! Sign up on the 2009 season of the Java Power Tools Bootcamps.

Related Topics >>