How to change POM version in CI build?

Viewed 2282

I'm probably approaching the problem all wrong, but here goes...

We want to implement a development -> releases/x.y.z -> master workflow using Gitlab and Nexus. The artifacts should be labelled x.y.z-SNAPSHOT, x.y.z-rc and x.y.z respectively.

In the ci-build.yml, I have tried to modify the POM depending on the current branch so as to create the correctly labelled artifacts. The problem is obviously that the change will be one commit ahead of the current build commit and the POM used in the build has the original version.

e.g.

  • a release branch is created from development
  • the POM has 2.3.4-SNAPSHOT and, during the ci-build, is modified to 2.3.4-rc and is committed and pushed to git
  • the subsequent build and deploy actions are executed but this deploys a 2.3.4-SNAPSHOT package to Nexus and not 2.3.4-rc as wanted

My question here is the following:

Can I modify the POM and use the updated POM in all following stages of the ci-build?

(I don't feel that this is the correct procedure, but it is what my team-leader has requested so I'm trying to implement it...)

1 Answers

My solution was to avoid commits altogether and use the strategy described in https://maven.apache.org/maven-ci-friendly.html.

This defines a new property, revision, which can be set using a maven parameter, -Drevision=x.y.z-SUFFIX. The POM version is set from this variable.

The build-ci reads project/properties/revision to extract the POM version and alters the version as appropriate depending on the current branch.

Using this approach I can achieve the required results without adding any extra commits as Maven can execute its goals using the version provided externally.

Related