18

I got a Sonatype Nexus instance up and running and need to write a script to download a specific artifact manually.

I tried using the REST API and wget:

wget --user=username --password=password http://<ip>:<port>/nexus/service/local/artifact/maven/content?g=<group>&a=<artifact>&v=<version>&r=snapshots

Resolving <ip stuff>
Connecting to <ipv6 stuff>... failed: Connection refused.
Connecting to <ipv4 stuff>... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Reusing existing connection to <ip>:<port>.
HTTP request sent, awaiting response... 400 Bad Request
2014-05-11 20:17:01 ERROR 400: Bad Request.

Does anyone know, how to get this to work?

Edit: I'm able to download the artifact using my browser (and being logged in to the webinterface)

dr0n3
  • 267
  • 1
  • 4
  • 12

3 Answers3

28

The URL looks correct, but you're to have to quote it because it contains special characters.

wget --user=username --password=password "http://<ip>:<port>/nexus/service/local/artifact/maven/content?g=<group>&a=<artifact>&v=<version>&r=snapshots"

You also might want to add --content-disposition in order for the downloaded file name to be correct. See here for more information:

https://support.sonatype.com/entries/23674267

Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
rseddon
  • 5,082
  • 15
  • 11
  • is there one for powershell? i got this on ps , Invoke-WebRequest : A positional parameter cannot be found that accepts argument '--password=admin123'. here is the command: wget --user=admin --password=admin123 "http://ec2-54-299-XX-231.us-west-2.compute.amazonaws. com:8081/nexus/service/local/artifact/maven/content?g=org&a=foo&v=1.0&r=releases" – OK999 Apr 27 '16 at 20:39
  • Your Sonatype link is broken: `The page you were looking for doesn't exist` – Boris Mar 24 '22 at 17:03
2

for nexus 3

wget --user=userid --password=password 'https://nexusurl:8081/nexus/repository/<repository id>/<replace the grouf is . with />/<artifact id>/<version>/<file name>' -O ${WORKSPACE}/<new file name>

example

group id =com.sap.cloudfoundry.mta_plugin_linux

artifact id =com.sap.cloudfoundry.mta_plugin_linux.api

nexus url = alm.xxxxxx.com

$WORKSPACE=jenkins present workspace

new filename=cf-cli-mta-plugin-2.0.3-linux-x86_64.bin

repository id = Sample_Replatform_Stage_2_Release (this you see as the name of the repo)

The command will be

 wget --user=USERID --password=PASSWORD 'https://alm.xxxxxxx.com/nexus/repository/sample_Replatform_Stage_2_Release/com/sap/cloudfoundry/mta_plugin_linux/com.sap.cloudfoundry.mta_plugin_linux.api/2.0.3/com.sap.cloudfoundry.mta_plugin_linux.api-2.0.3.bin' -O ${WORKSPACE}/cf-cli-mta-plugin-2.0.3-linux-x86_64.bin

most importantly for nexus rest api the artifactID-version should always match the filename else you will get the maven2 repository format error

for additional arguments and formats you may look in https://support.sonatype.com/hc/en-us/articles/213465488-How-can-I-retrieve-a-snapshot-if-I-don-t-know-the-exact-filename-

Subrata Fouzdar
  • 724
  • 5
  • 17
1

GNU Wget 1.20.3 built on darwin19.0.0. goes like this:

wget --http-user myusername --http-password=mypassword https://nexus.example.com/myfile.zip