Configure Jenkins to update pom.xml with buildnumbers

If you want to upload your jar/war files to nexus after each Jenkins build and want to have the buildnumber in the pom.xml, you can let Jenkins inject these.
You might also want this version in the manifest file in the jar/war so you can read the version from your program.

You first need to add the following to your pom.xml:



Note that you need to keep you major version in the tag!

In Jenkins, you can create a job called ‘update_version’ which changes the tag in your pom.xml.

pom_version=`mvn org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.version |grep -Ev '(^[|Downloadw+:)'`
mvn versions:set versions:commit -DnewVersion="$new_version"

Note that $BUILD_NUMBER is a Jenkins variable that is set with the current build number.

The script above searches the major version in the pom.xml and adds the builder version to it.

When you later deploy the project, both the pom.xml and the META-INF/MANIFEST.MF will have the new version.

In you software you can extract this version from the META-INF/MANIFEST.MF file that is packaged in your jar file.