Open a command prompt (Click Start > Run and type cmd). Use jre at the command prompt. This will return the Java JRE version number that is found in your path. Use java -version at the command prompt to check the version of the JDK in your path.
For a Release build/job: Build number is the Release number, read by Ant, from a Properties file. The properties file can also be distributed with the release for displaying the build number at runtime.
For several of my projects I capture the subversion revision number, time, user who ran the build, and some system information, stuff them into a .properties file that gets included in the application jar, and read that jar at runtime.
The ant code looks like this:
<!-- software revision number -->
<property name="version" value="1.23"/>
<target name="buildinfo">
<tstamp>
<format property="builtat" pattern="MM/dd/yyyy hh:mm aa" timezone="America/New_York"/>
</tstamp>
<exec executable="svnversion" outputproperty="svnversion"/>
<exec executable="whoami" outputproperty="whoami"/>
<exec executable="uname" outputproperty="buildsystem"><arg value="-a"/></exec>
<propertyfile file="path/to/project.properties"
comment="This file is automatically generated - DO NOT EDIT">
<entry key="buildtime" value="${builtat}"/>
<entry key="build" value="${svnversion}"/>
<entry key="builder" value="${whoami}"/>
<entry key="version" value="${version}"/>
<entry key="system" value="${buildsystem}"/>
</propertyfile>
</target>
It's simple to extend this to include whatever information you might want to add.
Your build.xml
...
<property name="version" value="1.0"/>
...
<target name="jar" depends="compile">
<buildnumber file="build.num"/>
<manifest file="MANIFEST.MF">
...
<attribute name="Main-Class" value="MyClass"/>
<attribute name="Implementation-Version" value="${version}.${build.number}"/>
...
</manifest>
</target>
...
Your java code
String ver = MyClass.class.getPackage().getImplementationVersion();
META-INF/maven/<project group>/<project id>/pom.properties
. The .properties file will contain the version property.Software:
Hudson has three builds/jobs: Continuous, Nightly and Release.
For a Continuous/Nightly build: Build number is the SVN revision, found using svntask.
For a Release build/job: Build number is the Release number, read by Ant, from a Properties file. The properties file can also be distributed with the release for displaying the build number at runtime.
The Ant build script puts the build number in the manifest file of jar/war files that are created during the build. Applies to all builds.
Post-build action for Release builds, done easily using a Hudson plug-in: tag SVN with the build number.
Benefits:
Hope this helps.
I'm using Hudson also, although a far more simpler scenario:
My Ant script has a target in it that looks like:
<target name="build-number">
<property environment="env" />
<echo append="false" file="${build.dir}/build-number.txt">Build: ${env.BUILD_TAG}, Id: ${env.BUILD_ID}, URL: ${env.HUDSON_URL}</echo>
</target>
Hudson sets these environment variables for me whenever my job runs.
In my case, this project is a webapp and I'm including this build-number.txt
file in the root folder of the webapp - I don't really care who sees it.
We don't tag source control when this is done because we already have our Hudson job set up to tag it with the build number/timestamp when the build is successful.
My solution only covers the incremental build numbers for development, we haven't gotten far enough in the project where we are covering release numbers yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With