5

I am using Azure pipelines (the .yml type) to build and publish an artifact from a Maven project.

Right now all I can do is publish artifacts with the exact version number that is defined in the project's pom.xml file, which is 1.0-SNAPSHOT

I would like the pipeline to automatically remove the -SNAPSHOT from it and update the patch version every time a new artifact is built and released, increasing the patch version based on the latest release. so it would be 1.0.1, then 1.0.2 after that, and so forth.

What should I change in the pom.xml or in the azure-pipelines.yml to make that happen?

jcm
  • 51
  • 1
  • 6
  • You may also try to create variable (e.g use the build number) and use the [Replace Tokens](https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens) extension task to replace the `` in the POM file by the variable. Reference this thread : https://stackoverflow.com/questions/58340380/how-to-manage-config-for-different-environments-like-dev-prod-uat-when-code-depl/58374232#58374232 – Andy Li-MSFT Mar 02 '20 at 09:16
  • @jcm Not get your response for several days, would you please share your latest information about this issue? If you have any concern, feel free to share it here. – Hugh Lin Mar 03 '20 at 06:00
  • As I explained in the comments for the answer I got, that alone does not solve the problem. I would still have to manually look up what the latest released version was, then add the new version number as a build parameter. I would like to automate this process. – jcm Mar 31 '20 at 14:01

1 Answers1

0

You can replace the content of <version> by ${revision}, add <revision>1.0-SNAPSHOT<revision> to the <properties> section of the POM.

Then you can override the value by adding -Drevision=1.0.1 on the command line.

Of course, to make this smooth, you need to write logic in your pipeline to read the original version and set the new version depending on this.

You can also try the following plugin

https://danielflower.github.io/multi-module-maven-release-plugin/

but I don't know if it works or not.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Adding the version number as a building parameter alone does not solve my problem, as I would still have to manually 1) check what was the latest version that was released and 2) manually insert the desired version in the pipeline script. I would like to automate these steps in the `azure-pipeline.yml` so that the patch version increases each time I publish an artifact, while the major and minor version of it are still defined in the `pom.xml` – jcm Feb 28 '20 at 11:46
  • As I said: I cannot offer a full solution (maybe someone else can), but you can read the version number from the POM in your pipeline, manipulate it (I don't know how scripting works in azure) and then set it as a command line parameter. – J Fabian Meier Feb 28 '20 at 12:07