How to add build number (from Jenkins) to jar file?

2.3k Views Asked by At

My application is build by Jenkins and Maven, I want to add the build number to jar file (this includes adding to the filename of the jar and also add the build number in the jar), potentially create a file that includes the version+build number in the jar, and I can also extract this info for other use, can someone help?

1

There are 1 best solutions below

6
On BEST ANSWER

Use should pass the build-number to the maven build so it will be set as part of the artifact version.

I recommend to use the version:set Maven plugin (see: https://www.mojohaus.org/versions-maven-plugin/set-mojo.html) in order to set the version name.

If you want to know what the current version of the project, use the following command, and then use the result combined with the build-number for setting the new version: mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version