-1

I am working on jenkins, maven, git project. I want to set the version in pom file to auto increment in every new build. I got the version using below command. Version no is 0.0.1.

grep -ri "<version>" pom.xml |head -n 1 | sed -e 's/^[ \t]*<version>\([^<]*\) 
<.*$/\1/' | sed 's/[-SNAPSHOT]//g'

Now I want to set that values into variables and increment the version in every new build. How can I do it? Is it possible to do? Next build output should be 0.0.2.

Can't I set 0.0.1 output into varibales like major, minor, bug and set $bug+1.

Janith
  • 217
  • 1
  • 6
  • 15

1 Answers1

0

Configure your pom with a new property for ex. revision as shown below

<version>${revision}</version>  
<properties>
    <revision>0.0.1</revision>

Increment the version passing the new version value as a parameter in your maven command as below or you can even use a variable for ex. new_version.

maven clean install -D revision=0.0.2

maven clean install -D revision="${new_version}"

https://maven.apache.org/maven-ci-friendly.html#Multi_Module_Setup

ben5556
  • 2,915
  • 2
  • 11
  • 16
  • This will produce WARNINGs in Maven cause this property is not supported. See my answer: https://stackoverflow.com/a/53099850/296328 – khmarbaise Nov 01 '18 at 10:58
  • From Macen 3.5.0-beta-1 We can define and use a revision property as described here https://maven.apache.org/maven-ci-friendly.html#Multi_Module_Setup – ben5556 Nov 01 '18 at 19:43
  • In the original post you have used a property `releaseVersion` which will produce a WARNING, cause only `revision`, `changelist` and `sha1` are the allowed properties. I know that you can use that cause I have implemented that and have written that page. – khmarbaise Nov 01 '18 at 20:49