【发布时间】:2017-10-06 04:45:00
【问题描述】:
我在 Nexus 3.x 中创建了一个原始存储库,并且可以将工件上传到该存储库。现在我想使用 Rest API 获取驻留在该仓库中的所有工件的列表。 任何帮助表示赞赏。
【问题讨论】:
-
你会想做类似的事情:stackoverflow.com/a/41070107/338597
我在 Nexus 3.x 中创建了一个原始存储库,并且可以将工件上传到该存储库。现在我想使用 Rest API 获取驻留在该仓库中的所有工件的列表。 任何帮助表示赞赏。
【问题讨论】:
在当前的 Nexus3.14.0-04 中,REST API 已成为最终版本(不再是“测试版”),您需要的 curl 是:
curl -X GET "http://localhost:8081/service/rest/v1/components?repository=central" -H "accept: application/json"
这将返回每个“组件”(组、名称、版本)及其所有资产 = 构成该组件的每个单独文件(pom、sha1、md5、jar)
结果是一个 JSON 字符串。
如果您想要执行 COMPONENTS 搜索 - 基于 groupId、artifactId - 您可以使用此 curl:
curl -X GET "http://localhost:8081/service/rest/v1/search?repository=central&format=maven2&maven.groupId=com.fasterxml.jackson.core&maven.artifactId=jackson-core&maven.extension=jar" -H "accept: application/json"
这将返回带有子资产的 COMPONENTS。
仅检索资产而不按组件分组的变体是 GET /service/rest/v1/search/assets?repository=central&format=maven2&maven.groupId=com.fasterxml.jackson.core&maven.artifactId=jackson- core&maven.extension=jar
【讨论】:
您可以使用 - 仍处于测试阶段 - Nexus 的新 API。它在 3.3.0 及更高版本上默认可用:http://localhost:8082/swagger-ui/
基本上,您从以下 URL 检索 json 输出:http://localhost:8082/service/siesta/rest/beta/assets?repositoryId=YOURREPO
一次只会显示 10 条记录,您必须使用提供的 continuationToken 来为您的存储库请求接下来的 10 条记录,方法是调用:http://localhost:8082/service/siesta/rest/beta/assets?continuationToken=46525652a978be9a87aa345bdb627d12&repositoryId=YOURREPO
更多信息在这里:http://blog.sonatype.com/nexus-repository-new-beta-rest-api-for-content
【讨论】: