Group Repo List via API


#1

Continuing the discussion from Advanced Use Cases for the Nexus Repository Manager API:

Another handy script for listing out the repositories that are members of a repo group.

Group Repo List via API

API Version:

import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import org.sonatype.nexus.repository.config.Configuration;

//expects json string with appropriate content to be passed in
def repo = null
if (args?.trim()) {
repo = new JsonSlurper().parseText(args)
}

String groupRepoName = repo?.name

Configuration groupRepoConfig = repository.repositoryManager.get(groupRepoName).getConfiguration();

return JsonOutput.toJson(groupRepoConfig.getAttributes().group.memberNames)


or Scheduled Task Version (the member list will go into your nexus.log):

import org.sonatype.nexus.repository.config.Configuration;
Configuration groupRepoConfig = repository.repositoryManager.get(“npm-public”).getConfiguration();
log.info
(“Group Repo Config: ${groupRepoConfig.getAttributes().group.memberNames}”)