Reputation: 33
I'm building artifacts by jenkins and uploading them to maven2 repo in OSS Nexus 3.6 by nexusArtifactUploader on every git commit. On tagged commit it's uploading as release with version mentioned in git tag; untagged commits are published as snapshots of last git tag's version.
Everyone has RO access to that repository, so I don't need to specify any credentials in order to download the artifact.
On the deploy stage I'm downloading artifacts by links like nexus_url/repository/my-repo-releases/com/example/somthing/my_artifact/1.0.15/my_artifact-1.0.15.jar . But I want to download the latest release via link like nexus_url/repository/my-repo-releases/com/example/something/my_artifact/latest (I don't want to specify release number, I just want to have latest).
Could you please tell me how to do that? It looks like the basic operation for every repository. I'm not sure if I should write some scripts using nexus API - or shell I?
Upvotes: 1
Views: 1370
Reputation: 257
Currenctly Nexus 3 does not provide the "latest"-function as you know from Nexus 2. It only provides a simple REST API.
I did this with a Python script. The URL(s) you have to query look like this:
request_url = nexus_url + "/service/siesta/rest/v1/assets?repositoryId=" + repository_id
In the response you will receive 5 random entries of your artifacts containing the download URL, other attributes and a continuation token. So you can iterate (while you have a continuation token present) through all artifacts using the continuation token.
request_url = nexus_url + "/service/siesta/rest/v1/assets?continuationToken=" + response["continuationToken"] + "&repositoryId=" + repository_id
Extract the artifact-version from the downloadURL, save this and the version to a OrderedDictionary, get the highest artifact number (max. value) and use its download URL:
od = collections.OrderedDict(sorted(all_download_urls.items()))
download_key = max(od)
if bool(max(od)):
download_url = od.get(download_key)
print "Downloading this version: "
print download_key
print "---------------------------"
print "Using this download url"
print download_url
os.system("wget %s --user=%s --password=%s" % (download_url, user, password))
else:
print "Not found."
To be honest I really don´t know why Sonatype released Nexus3 without the "latest" function...
EDIT
I wrote this script for Nexus 3.3.x so on 3.6 the URL or the attributes returned from the REST call might differ a bit.
Upvotes: 0