Reputation: 1598
According to https://www.cloudbees.com/blog/new-way-do-continuous-delivery-maven-and-jenkins-pipeline how should writing to a pom with pom.version.replace look like? I assume that pom.version.replace doesn't modify anything but how can the change be saved in pom? I'm currently using this which fails with the update:
def pom = readMavenPom file: 'pom.xml'
def version = pom.version.replace("-SNAPSHOT", "")
writeMavenPom model: pom
Upvotes: 3
Views: 2712
Reputation: 1598
I had to add following instruction to save the data:
pom.version = pom.version.replace("-SNAPSHOT", "")
Although there are better options
Upvotes: 0
Reputation: 8267
I recommend you to use maven versions plugin.
Ypu can remove -SNAPSHOT with this command:
mvn versions:set -DremoveSnapshot
Upvotes: 1
Reputation: 2324
Being inspired from a link I just pasted as a comment to another answer, you could as well have some look into new Maven features for continuous delivery. Namely, you can use properties now (starting with Maven 3.2.1) as a version:
<version>${releaseVersion}</version>
...
<properties>
<releaseVersion>0-SNAPSHOT</releaseVersion> <!-- sane default -->
</properties>
So you could just pass your desired version during the build as a -D
parameter:
mvn clean package -DreleaseVersion=1.2.3-45
See here for a detailed discussion: https://axelfontaine.com/blog/dead-burried.html
Upvotes: 1
Reputation: 11490
You need to change the pom object. The replace
method will not modify the string but return a new one. Since you already stored the changed version you just need to overwrite the pom.version
. The object returned by readMavenPom
is a Model. This class has a setVersion
method which can be used to change the version before writing the object with writeMavenPom
to file.
So it should look like this:
def pom = readMavenPom file: 'pom.xml'
def version = pom.version.replace("-SNAPSHOT", "")
pom.version = version
writeMavenPom model: pom
Upvotes: 3