如何使用wget从Sonatype Nexus下载构件。

18

我已经安装并运行了Sonatype Nexus实例,需要编写一个脚本手动下载特定的构件。

我尝试使用REST API和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.

有人知道如何让这个工作吗?

编辑:我能够使用我的浏览器(并登录到Web界面)下载该构件。

3个回答

28

URL看起来正确,但您需要将其引用,因为它包含特殊字符。

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

您还可能想要添加--content-disposition,以便下载的文件名是正确的。更多信息请参见此处


有 PowerShell 的版本吗?我在 PowerShell 上得到了这个错误:Invoke-WebRequest:找不到接受参数'--password=admin123'的位置参数。以下是命令: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
你的Sonatype链接已经失效:您正在查找的页面不存在 - Boris

2
为了 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>

示例

组ID = com.sap.cloudfoundry.mta_plugin_linux

构件ID = com.sap.cloudfoundry.mta_plugin_linux.api

Nexus URL = alm.xxxxxx.com

$WORKSPACE = Jenkins当前工作区

新文件名 = cf-cli-mta-plugin-2.0.3-linux-x86_64.bin

仓库ID = Sample_Replatform_Stage_2_Release(您将其视为repo的名称)

命令将是

 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

对于 Nexus Rest API 来说,最重要的是 artifactID-version 应该始终与文件名匹配,否则您将收到 Maven2 存储库格式错误的提示。

如果您需要额外的参数和格式,请查看 https://support.sonatype.com/hc/en-us/articles/213465488-How-can-I-retrieve-a-snapshot-if-I-don-t-know-the-exact-filename-


1

GNU Wget 1.20.3 在 darwin19.0.0 上构建,如下所示:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接