简体   繁体   English

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

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

Maybe I miss something but i can't find a way to upload a component(jar or dll) to the nexus 3 repository from the UI.也许我错过了一些东西,但我找不到从 UI 将组件(jar 或 dll)上传到 nexus 3 存储库的方法。 So I am trying to build a tool for this job, to optimize the upload process I need a way to check if component exist in the nexus repository programmatically, all my tries to find suitable rest api failed.因此,我正在尝试为这项工作构建一个工具,以优化上传过程,我需要一种方法来以编程方式检查 nexus 存储库中是否存在组件,但我试图找到合适的 rest api 的所有尝试都失败了。

Anyone have suggestions?有人有建议吗?

Maybe you can upload a groovy script and use that script to check whether the component exists or not.也许您可以上传一个 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;

At this time, the REST API has been released as beta.目前,REST API 已作为测试版发布。 You can get more information and give us feedback by going to this link: http://blog.sonatype.com/nexus-repository-new-beta-rest-api-for-content您可以通过以下链接获取更多信息并向我们提供反馈: http : //blog.sonatype.com/nexus-repository-new-beta-rest-api-for-content

You can use some of the new endpoints to check if a component/asset exists, and then use curl or something akin depending on the format to upload it via the existing format endpoints.您可以使用一些新端点来检查组件/资产是否存在,然后根据格式使用 curl 或类似的东西通过现有格式端点上传它。

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

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