Nexus IQ & Nexus Repository Jenkins Configuration By Code

Can someone point me to the Nexus Jenkins plugin configuration API documentation in order for me configure via code the initial settings of the nexus plugin.

For example i want to do something like this from within jenkins init_groovy_d

pseudo code…

import nexus-platform-plugin.?? // some class library
instance = jenkinsInstance()

def nexusConfig = instance.getDescriptorByType(Nexus.class ???) // some class i dont know
nexusConfig.Repository.DisplayName = “DisplayName”; // some class properties
nexusConfig.Repository.ServerId = “NexusPrivateRepository”;
// more nexus repos config properties etc…etc…

nexusConfig.IQ.ServerUrl = “https://blob
// more nexus iq config props… etc…etc

This would give me something like this…

Thanks in advance.

For anyone else looking here is a starter implementation

Note that (1) we can programatically add multiple Nexus IQ servers (there are no guards) but in the GUI only one is allowed…

Most of this is logging … maybe someone can tidy it up

// this is all inferred from 
// https://github.com/jenkinsci/nexus-platform-plugin/tree/master/src/main/java/org/sonatype/nexus/ci/config
//
// org.sonatype.nexus.ci.config.NxiqConfiguration
// org.sonatype.nexus.ci.config.Nxrm2Configuration
// org.sonatype.nexus.ci.config.Nxrm3Configuration
//

import groovy.transform.Field
import java.util.logging.Logger;
import org.sonatype.nexus.ci.config.*
import com.cloudbees.plugins.credentials.*;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
  
@Field String CREDENTIAL_NAME = "???";
@Field String NXRM_DISPLAY_NAME = "???";
@Field String NXRM_SERVER_ID = "???";
@Field String NXRM_SERVER_URL = "???";
@Field String NXIQ_SERVER_URL = "???";

@Field Logger logger = Logger.getLogger("");
@Field def instance = Jenkins.getInstance()
@Field String displayName;
////////////
def globalConfig = instance.getDescriptorByType(GlobalNexusConfiguration.class)
if(globalConfig == null)
{
  logger.severe("Unable to find the Nexus repository plugin have you installed 'nexus-platform-plugin'");
  println("Nexus plugin not found :: see (Manage Jenkins -> System Logs)");
  return;
}

def credentials = CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, instance);
def credential = credentials.find { it.id == CREDENTIAL_NAME };
if(credential == null) {
  logger.severe("Shared Libraries: No credentials found, cannot proceed.");
  println("Credential not found :: see (Manage Jenkins -> System Logs)");
  return
}
displayName = globalConfig.getDisplayName();

// configure the plugin...
ConfigureNexusRepository(globalConfig.nxrmConfigs);
ConfigureNexusIQ(globalConfig.iqConfigs);
instance.save();

println("Successfully updated the configuration :: see (Manage Jenkins -> System Logs)");
//// END...
  
def ConfigureNexusRepository(List<Nxrm3Configuration> nxrmConfigs)
{ 
  nxrmConfigs.each { v ->
    logger.info("${displayName}::Before ==> '${v.getDisplayName()}', '${v.getInternalId()}','${v.getServerUrl()}','${v.getCredentialsId()}'"); 
  }
  
  // first add a new nexus repos config
  nxrmConfigs.removeIf { v -> v.getDisplayName() == NXRM_DISPLAY_NAME };
  String internalId = UUID.randomUUID().toString(); // we need to provide an internal-id as guid unique across instances
  def nxrm3 = new Nxrm3Configuration(/*id*/NXRM_SERVER_ID, /*internalId*/internalId, /*displayName*/NXRM_DISPLAY_NAME, /*serverUrl*/NXRM_SERVER_URL, /*credentialsId*/CREDENTIAL_NAME);
  nxrmConfigs << nxrm3
  
  nxrmConfigs.each { v ->
    logger.info("${displayName}::After ==> '${v.getDisplayName()}', '${v.getInternalId()}','${v.getServerUrl()}','${v.getCredentialsId()}'"); 
  }
}

def ConfigureNexusIQ(List<NxiqConfiguration> iqConfigs)
{
  iqConfigs.each { v ->
    logger.info("${displayName}::Before ==> '${v.getServerUrl()}', '${v.getCredentialsId()}'");   
  } 	
  // next add a new next iq config -- should only be one so may juse clear()
  // getServerUrl() actually returns a java.net.URI
  iqConfigs.removeIf { v -> v.getServerUrl().toString() == NXIQ_SERVER_URL }; 
  def nxiq = new NxiqConfiguration(/*serverUrl*/NXIQ_SERVER_URL, /*credentialsId*/CREDENTIAL_NAME);
  iqConfigs << nxiq
  
  iqConfigs.each { v ->
    logger.info("${displayName}::After ==> '${v.getServerUrl()}', '${v.getCredentialsId()}'");   
  }
}