Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get maven deployment URL during/after deployment

I have a Java project. It has a pom.xml set up and I use mvn deploy to deploy new artifacts to an internal company Nexus. And everything is working fine.

But... I'm working on integrating this application in a CI/CD system. So, basically what I need is to programmatically / automatically know where this artifact was deployed (the exact Nexus URL of the artifact) so I can include this as input for the next step of the CI/CD system.

I know this usually isn't needed when working with Maven. But what can I say, I need this URL to appear on some web page which shows this artifact, along with some other info related to it, like which tests were run on it, who created it, when, on top of which commit of which repository it was built etc...

So... Is there a nice, clean way for me to get this info, apart from the hackish way of manually parsing the pom.xml file to try to recreate the URL. Something like mvn give-me-the-url-to-which-you-would-deploy-if-i-were-to-run-deploy. :)

like image 1000
morgoth84 Avatar asked Oct 17 '17 11:10

morgoth84


People also ask

Where does mvn deploy deploy to?

The maven deploy plugin can be used to deploy either files or projects to the remote repository for sharing it with other developers and projects. There are various methods can be used to deploy your artifact to the remote repository by using a maven deploy plugin.

What is distributionManagement in Maven?

Where as the repositories element specifies in the POM the location and manner in which Maven may download remote artifacts for use by the current project, distributionManagement specifies where (and how) this project will get to a remote repository when it is deployed.

What happens on mvn deploy?

deploy:deploy is used to automatically install the artifact, its pom and the attached artifacts produced by a particular project. Most if not all of the information related to the deployment is stored in the project's pom. deploy:deploy-file is used to install a single artifact along with its pom.

What is the difference between mvn install and mvn deploy?

mvn:install copies your packaged Maven module to your local repository (by default, in ~/. m2/repository ), to be accessed by other local Maven builds. mvn:deploy uploads your packaged Maven module to another (usually remote) repository, to be accessed by other, not necessarily local, Maven builds.


1 Answers

A direct, but a little bit hacky way would be to read the Maven log file. It contains lines like

Uploaded: http://ik-re1.continentale.loc:8082/nexus/content/repositories/snapshots/de/continentale/spu/rrep-pjava-index/2.3.4-SNAPSHOT/rrp-pjav-index-2.3.4-20170901.115031-18-sources.jar (202 KB at 2459.3 KB/sec)

These lines tell you the exact URLs, but you need to parse a text file.

like image 191
J Fabian Meier Avatar answered Sep 22 '22 01:09

J Fabian Meier