如何使用curl将文件上传到Nexus存储库管理器?

时间:2019-01-09 09:16:30

标签: curl nexus snapshot

我正在尝试使用以下命令将文件上传到Nexus 2.14.11-01服务器上的快照存储库:

curl -v -u username:password --upload-file file.ext \
    https://example.com/nexus/content/repositories/snapshots/ \
    com.example.snapshot/com/example/myscripts/1.2.3/file-1.2.3-SNAPSHOT.ext

应符合此support page的要求。就我而言,它失败并显示以下输出:

*   Trying xxx.xxx.xxx.xxx...
* Connected to example.com (xxx.xxx.xxx.xxx) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 597 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
*    server certificate verification OK
*    server certificate status verification SKIPPED
*    common name: *.example.com (matched)
*    server certificate expiration date OK
*    server certificate activation date OK
*    certificate public key: RSA
*    certificate version: #3
*    subject: -
*    start date: Thu, 02 Nov 2017 00:00:00 GMT
*    expire date: Thu, 13 Feb 2020 12:00:00 GMT
*    issuer: C=US,O=DigiCert Inc,CN=DigiCert SHA2 Secure Server CA
*    compression: NULL
* ALPN, server accepted to use http/1.1
* Server auth using Basic with user 'username'
> PUT /nexus/content/repositories/snapshots/com.example.snapshot/com/example/myscripts/1.2.3/file-1.2.3-SNAPSHOT.ext HTTP/1.1
> Host: example.com
> Authorization: Basic dHyZXcabzpAbmVlMjVa
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 7837
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 403 Forbidden
< Date: Wed, 09 Jan 2019 09:06:14 GMT
< Server: Nexus/2.14.11-01
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Content-Length: 0
< Access-Control-Allow-Origin: *
< 
* Connection #0 to host example.com left intact

2 个答案:

答案 0 :(得分:2)

首先,您得到403(禁止访问),表示您的登录凭据已被接受,但是执行上载的用户没有上载到存储库的权限。

第二,该文件不是有效的Maven存储库布局。它必须采用以下形式:

  

/ $ groupIdWithSlashes / $ artifactId / $ version / $ artifactId- $ version。$ extension
  /$groupIdWithSlashes/$artifactId/$version/$artifactId-$version-$classifier.$extension

https://example.com/nexus/content/repositories/snapshots/ \
    com.example.snapshot/com/example/myscripts/file/ \
    1.2.3-SNAPSHOT/file-1.2.3-SNAPSHOT.ext

第三,您确实应该使用maven进行上传,因此将生成一个pom文件。 Maven存储库中的工件应始终具有关联的pom文件。使用“ deploy:deploy-file” maven目标将生成一个pom:

https://support.sonatype.com/hc/en-us/articles/213465818-How-can-I-programmatically-upload-an-artifact-into-Nexus-2-#maven-deploy-file

答案 1 :(得分:0)

唯一的问题是,在 curl 命令中使用用户和密码令牌代码,而不是纯文本值

curl -v -u username_token_code:password_token_code --upload-file file.ext \
    https://example.com/nexus/content/repositories/snapshots/ \
    com.example.snapshot/com/example/myscripts/1.2.3/file-1.2.3-SNAPSHOT.ext

How to generate User and Password token code