I'm trying to download an artifact uploaded to nexus using CURL. But I'm unable to get it downloaded. The below command execution from command prompt doesn't download the required zip file and I'm using Nexus admin account
curl -X GET -u userid:pwd "http://nexusserver:8081/nexus/service/local/artifact/maven/redirect?r=Repo_Name&g=GroupID&a=artifactID&v=LATEST&p=zip" -O
Did I form the URL correctly? I tried to browse the URL (http://nexusserver:8081/nexus/service/local/artifact/maven/redirect?r=Repo_Name&g=GroupID&a=artifactID&v=LATEST&p=zip), but got HTTP 404 Not found in Nexus Repository Manager. I'm using Nexus version 3.0.2-02. I'm new to nexus and any help is greatly appreciated.
Thanks
How to download a file with curl command. The basic syntax: Grab file with curl run: $ curl https://your-domain/file.pdf. Get file using ftp or sftp protocol: $ curl ftp://ftp-your-domain-name/file.tar.gz.
To download the latest Nexus Repository Manager OSS distribution, go to Sonatype's OSS download page and choose the compressed bundle file that suits your need from the Nexus Repository Manager OSS 2. x section. A download will begin to the latest version. Older versions can be found here if needed.
In newer versions of nexus you can:
On bash this boils down to:
$ curl -sSL -X GET -G "http://mynexus3.local/service/rest/v1/search/assets" \
-d repository=maven-snapshots \
-d maven.groupId=my.group.id \
-d maven.artifactId=my-artifact \
-d maven.baseVersion=1.0-SNAPSHOT \
-d maven.extension=jar \
-d maven.classifier=jar-with-dependencies \
| grep -Po '"downloadUrl" : "\K.+(?=",)' \
| xargs curl -fsSL -o my-artifact.jar
The first block will search for your artifact and output something similar to
{
"items" : [ {
"downloadUrl" : "http://mynexus3.local/repository/maven-snapshots/my/group/id/my-artifact/1.0-SNAPSHOT/my-artifact-1.0-20180821.085657-1-jar-with-dependencies.jar",
"path" : "/my/group/id/my-artifact/1.0-SNAPSHOT/my-artifact-1.0-20180821.085657-1-jar-with-dependencies.jar",
"id" : "foo",
"repository" : "maven-snapshots",
"format" : "maven2",
"checksum" : {
"sha1" : "bar",
"md5" : "baz"
}
} ],
"continuationToken" : null
}
Then you can use grep or something similar to extract the download URL. Finally you pass the extracted URL to curl again to download your artifact. (tested with Nexus 3.13)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With