1

Whenever I run my jenkins build I want my snapshot version to be auto incremented. I do understand there are several plugins to them, just trying to understand is there a way to achieve this without any pluggins?

Meister96Fels
  • 508
  • 1
  • 8
  • 26
user11881
  • 65
  • 2
  • 12

2 Answers2

0

You can change your artifact version automatically - by specifying it as ${env.BUILD_NUMBER} (for example) in your Jenkins pipeline and then pass it as a {revision} parameter to mvn command. To do this, you need to put this {revision} variable into <version> tag like following

<version>${revision}</version> 

and then provide it to the maven command in Jenkins pipeline:

mvn deploy -Drevision=${env.BUILD_NUMBER}

See this answer (1st option) for details.

Note: as @khmarbaise pointed out, you have to use the flatten-maven-plugin, otherwise there could be some issues, see details in this article. (However, in my case for simple maven project there were no such problems, so I didn't use that plugin, only revision parameter)

biruk1230
  • 3,042
  • 4
  • 16
  • 29
  • Why not? From that article you can see that if you're using a command like `mvn deploy -Drevision=${env.BUILD_NUMBER}`, then it will work correctly. I think that if you're using automated builds in Jenkins, then it will not be a problem to add `-Drevision=${env.BUILD_NUMBER}` argument. And I don't see better option for auto incrementing version in Jenkins build without adding a parameter to `mvn` command. – biruk1230 Jan 22 '19 at 13:16
  • You have not read until the end of the documentation (flatten-maven-plugin). If you use your setup you resulting pom files will be errornous..means you can't consume them..!! (See here: https://maven.apache.org/maven-ci-friendly.html) – khmarbaise Jan 22 '19 at 14:45
  • As I understand, it's only for multi module projects, for simple project all is fine (I already tried that). Thanks for pointing out! – biruk1230 Jan 22 '19 at 14:54
  • Not sure, I've used `revision` parameter without flatten-maven-plugin, and all was working perfectly without any issues. Anyway, added your info above, thanks! – biruk1230 Jan 22 '19 at 15:04
  • thanks @biruk1230 .. i tried using revision and ran into some errors – user11881 Jan 22 '19 at 17:26
-1

You can use versions-maven-plugin

mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} versions:commit

The Goal “build-helper:parse-version” provides parse fragments of the actual version in the pom.xml and calculates also the incremented fragments of the version: Use can use this vars to setup new version

parsedVersion.nextMajorVersion
parsedVersion.nextMinorVersion
parsedVersion.nextIncrementalVersion
Tirex
  • 454
  • 4
  • 7