Wednesday Jan 27, 2010

Maven and Hudson Trick

Like many projects the Java Store uses Maven for our build description and Hudson for our continuous integration.

We've been trying to do a bit more lately with tagging the build outputs with version and build information for later tracking. Hudson provides a number of environment variables which describe the build environment to Maven (or Ant). We're starting to use some of those variables in our output manifests and elsewhere. However, when building the projects locally the Hudson build variables aren't defined. So I came up with a little recipe which can be added to pom files to provide default values when the project isn't being built by Hudson.

The values used aren't always the best match for the values Hudson would supply but they are the closest I could come up with without adding additional requirements. For your projects you may want to tweak the values used.

Surrogate Hudson Build Variables
<profile>
    <id>Hudson Surrogate Params</id>
    <properties>
        <env.BUILD_NUMBER>UNKNOWN</env.BUILD_NUMBER>
        <env.BUILD_ID>${maven.build.timestamp}</env.BUILD_ID>
        <env.JOB_NAME>${project.name}</env.JOB_NAME>
        <env.BUILD_TAG>${user.name}-${env.JOB_NAME}-${project.version}_${env.BUILD_NUMBER}-${env.BUILD_ID}</env.BUILD_TAG>
        <env.EXECUTOR_NUMBER>0</env.EXECUTOR_NUMBER>
        <env.WORKSPACE>${basedir}</env.WORKSPACE>
        <env.HUDSON_URL>UNKNOWN</env.HUDSON_URL>
        <env.SVN_REVISION>rUNKNOWN</env.SVN_REVISION>
    </properties>
    <activation>
        <property>
            <!-- Activated if Hudson hasn't already set the BUILD_NUMBER -->
            <name>!env.BUILD_NUMBER</name>
        </property>
    </activation>
</profile>
EDIT (20100429) : I have updated the sample source slightly.
About

mduigou

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today