繁体   English   中英

Nexus 3 Rest api 来检查组件是否存在

[英]Nexus 3 Rest api to check if component exist

也许我错过了一些东西,但我找不到从 UI 将组件(jar 或 dll)上传到 nexus 3 存储库的方法。 因此,我正在尝试为这项工作构建一个工具,以优化上传过程,我需要一种方法来以编程方式检查 nexus 存储库中是否存在组件,但我试图找到合适的 rest api 的所有尝试都失败了。

有人有建议吗?

也许您可以上传一个 groovy 脚本并使用该脚本来检查该组件是否存在。

import org.sonatype.nexus.repository.storage.Query;
import org.sonatype.nexus.repository.storage.StorageFacet;
import groovy.json.JsonOutput;

def repositoryId = args.split(',')[0];
def groupId = args.split(',')[1];
def artifactId = args.split(',')[2];
def baseVersion = args.split(',')[3];
def latestOnly = args.split(',')[4];

def repo = repository.repositoryManager.get(repositoryId);
StorageFacet storageFacet = repo.facet(StorageFacet);
def tx = storageFacet.txSupplier().get();

tx.begin();
def components = tx.findComponents(Query.builder().where('group = ').param(groupId).and('name = ').param(artifactId).build(), [repo]);

def found = components.findAll{it.attributes().child('maven2').get('baseVersion')==baseVersion}.collect{
def version = it.attributes().child('maven2').get('version');\"${version}\"};

// found = found.unique().sort();
def latest = found.isEmpty() ? found : found.last();

tx.commit();
def result = latestOnly == 'latest' ? JsonOutput.toJson(latest) : JsonOutput.toJson(found);

return result;

目前,REST API 已作为测试版发布。 您可以通过以下链接获取更多信息并向我们提供反馈: http : //blog.sonatype.com/nexus-repository-new-beta-rest-api-for-content

您可以使用一些新端点来检查组件/资产是否存在,然后根据格式使用 curl 或类似的东西通过现有格式端点上传它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM