Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download artifacts using wget from Sonatype Nexus

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)

like image 316
dr0n3 Avatar asked May 11 '14 18:05

dr0n3


People also ask

How do I download from Nexus repository?

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.

How do I download a package using wget?

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.

How do I download artifacts from Nexus to Jenkins?

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.

How do I add artifacts to Sonatype nexus?

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.


2 Answers

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

like image 78
rseddon Avatar answered Sep 30 '22 18:09

rseddon


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-

like image 20
Subrata Fouzdar Avatar answered Sep 30 '22 17:09

Subrata Fouzdar