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)
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 order to download a file using Wget, type wget followed by the URL of the file that you wish to download. Wget will download the file in the given URL and save it in the current directory.
Your Nexus user, at least, should have read access to the repository which has the artifact. For this, go to Jenkins homepage-> Manage Jenkins -> Manage Credentials page. Then click the global link under Domains. Now, click Add Credentials.
Maven - Uploading a Pom File with Artifacts To upload a pom file and its associated artifacts add all the files into the upload screen at the same time. Be sure to specify the extension of the pom file as pom ; this will let Nexus Repository know it should be taking the coordinates from the pom file, not the UI.
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
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-
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