Nexus 3 Rest api to check if component exist
Asked Answered
C

2

1

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. 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.

Anyone have suggestions?

Carolyncarolyne answered 18/3, 2017 at 11:24 Comment(0)
K
1

At this time, the REST API has been released as beta. 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

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.

Kimberlite answered 26/9, 2017 at 21:46 Comment(0)
C
2

Maybe you can upload a groovy script and use that script to check whether the component exists or not.

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;
Carswell answered 7/6, 2017 at 2:45 Comment(0)
K
1

At this time, the REST API has been released as beta. 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

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.

Kimberlite answered 26/9, 2017 at 21:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.