In our Web application, we have a About page. In that page we show, the version number+build number of the product. This is an easy way for us to find out which version+build number of the application is deployed to the server. This also helps the QA to indentify the build number when they file a bug during development. We wanted this build number to be automatically updated. Our build deploysautomate this process.
Continuous Integration server: Hudson/Jenkins
Builds using Maven
Steps:
We are going to use the filter capabilities of Maven during build.
We will open application.properties file where we will put in the Macro for filling the build number during build
Example,
app.grails.version=1.3.7
app.name=Sample
app.servlet.version=2.4
app.version=1.1-SNAPSHOT
app.build.no=${BUILD_NUMBER}
${BUILD_NUMBER} is the macro filled in by Jenkins during build
Next, we have to tell maven to let Hudson fill this macro during build.
In pom.xml,
inside the build tag add the following,
<build>
<resources>
<resource>
<directory>${basedir}</directory>
<filtering>true</filtering>
<includes>
<include>application.properties</include>
</includes>
</resource>
</resources>
.....
</build>
With the above steps after the build, application.properties file will be populated by the latest build number by Jenkins.
Now the last step,
We have to make use of this build number in our application.
Wherever you need to show this information(in our case help.gsp), do the following,
Build no: <g:meta name="app.build.no"/>
tag gets the value for the key “app.build.no” in application.properties file. This value will be a valid number after a successful build.
Thats it!