Search code examples
awkwgetnexussonatypenexus3

Download latest snapshot artifact from Nexus Repository Manager OSS 3.30.0-01using wget/curl command


I am facing difficulty downloading the latest snapshot version from Nexus Repository Manager OSS 3.30.0-01 using wget /curl

the problem I am facing is that in nexus there are multiple version of artefacts within the same snapshot version appended with timestamp plus - an incremental number like the below image

enter image description here

enter image description here enter image description here

so how to download the latest snapshot version from multiple version under one snapshot?

currently, I have to specify explicitly specify the version like the below one

wget http://$NEXUS_URL/repository/mfi-snapshots/com/mf/productService/1.0.9-SNAPSHOT/productService-1.0.9-20210329.141405-11.war

So is there any way to download the latest version with just mentioning the snapshot version and download the latest ver

 $NEXUS_URL: is the nexus URL 
mfi-snapshots: is the snapshot repo
com.mf: is the group 
productService is the artefact
1.0.9 SNAPSHOT the version of the artefact

I tried to use "/v1/search/assets/download" API defined in nexus ( not sure how to use it

http://$NEXUS_URL/service/rest/v1/search/assets/download?sort=version&direction=desc&q=war&repository=mfi-snapshots&group=com.mf&name=productService

which given a json output like enter image description here


Solution

  • I followed the steps mentioned in help article on sonatype and I got the solution

    https://help.sonatype.com/repomanager3/rest-and-integration-api/search-api#SearchAPI-DownloadingtheLatestVersionofanAsset

    curl -L -o productService.war  -s -X GET "$NEXUS_HOST/service/rest/v1/search/assets/download?sort=version&repository=$NEXUS_SNAPSHOTS_REPO&maven.groupId=com.mf&maven.artifactId=productService&maven.baseVersion=$SNAPSHOT_VERSION&maven.extension=war" -H "accept: application/json"