|
|
||
John Ferguson Smart's Blog
«Continuous Integration build strategies - stage your builds! |
Main
| Cool ways to use Hudson - voice control »
Using Hudson environment variables to identify your buildsUsing Hudson environment variables to identify your buildsPosted by johnsmart on March 09, 2008 at 08:21 PM | Comments (0)So your CI server now automatically deploys your application to an integration server. You've even configured it so that you can manually deploy to the QA server using the same process. Great! But wouldn't it be nice to know exactly what build you are looking at at any point in time? Well, Hudson lets you do just that. When Hudson runs a build, it passes in a few useful environment variables, that you can use in your build script. This is a great way to inject information about the build into your deployable application. For example, Hudson build has a unique number, which you can reference in your build scripts using something like "${BUILD_NUMBER}". This is the list of variables (taken from an obscure corner of the Hudson documentation :-)):
Sweet, you say. But how can you inject this into your deployable application? Easy. Just use these variables as you would any other properties, and let your imagination do the rest! In a Maven project, for example, you can use the maven-war-plugin plugin to inject data into the MANIFEST.MF file as follows: <project>...<build>...<plugins><plugin><artifactId>maven-war-plugin</artifactId><configuration><manifest><addDefaultImplementationEntries>true</addDefaultImplementationEntries></manifest><archive><manifestEntries> Now, the WAR file generated by Hudson will contain the build number: Manifest-Version: 1.0 It is then a simple matter to extract this field from the MANIFEST.MF file of your deployed application at runtime. The java.util.jar.Manifest comes in handy here. I use this to display the build version discretly at the bottom of the screen so that testers can identify exactly what version they are dealing with. I'll be giving a 4 day Java Power Tools Bootcamp in San Francisco, from May 12 to May 15 just after JavaOne. So, if your in SF at this time, come along! Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment | ||
|
|