Victor Bouhnik
Victor Bouhnik

Reputation: 308

maven release plugin - manipulating project release version

I'm trying to configure in Jenkins a maven release build with customized release version that includes the branch from which the release was made.

It looks something like this:

release:prepare -DreleaseVersion=${project.version}-${GIT_LOCAL_BRANCH}-Release release:perform

everything works fine, except that the 'project.version' placeholder, which calculated based on the pom, contains the '-SNAPSHOT' postfix.

is there other placeholder which I can use to get it without the '-SNAPSHOT'? I know that the maven release plugin, by default, will set the right version - only I want to manipulate that value.

Upvotes: 2

Views: 2471

Answers (2)

newur
newur

Reputation: 520

See the offical docu https://maven.apache.org/maven-ci-friendly.html.

There are 3 properties maven supports since 3.5: ${revision}, ${sha1} and ${changelist}. So you can use something like

<version>${revision}${changelist}</version>
  ...
<properties>
  <revision>1.3.1</revision>
  <changelist>-SNAPSHOT</changelist>
</properties>

And call it with

release:prepare -DreleaseVersion=${revision}-${GIT_LOCAL_BRANCH}-Release

But the maven-release-plugin does not work nicely together with the CI friendly versions. Read: it will probably overwrite your placeholders in the version tag. So in the end you might just manipulate the -SNAPSHOT string via bash commands.

Upvotes: 1

D.B.
D.B.

Reputation: 4713

is there other placeholder which I can use to get it without the '-SNAPSHOT'?

Unfortunately I believe the answer to your question is "no, there is no built-in variable that will satisfy your needs". However, you could try creating a property and then using that property inside of your project's version tag.

I am not able to test this as I don't have the appropriate environment set up and it's rather late so I'm not going to have the time to set it up right now. I will outline my idea and perhaps it will help you:

You could do something like this in your POM:

<version>${artifactReleaseVersion}-SNAPSHOT</version>
<properties>
    <artifactReleaseVersion>0.0.1</artifactReleaseVersion>
</properties>

Then run your goals using that property:

release:prepare -DreleaseVersion=${artifactReleaseVersion}-${GIT_LOCAL_BRANCH}-Release release:perform

Upvotes: 0

Related Questions