The nexus puzzle in continuous integration

Subrata Fouzdar
4 min readSep 20, 2018

As a DevOps engineer setting up a repository manager is pretty much a defacto requirement. Nexus being one of them , I stumbled up on it many times. Trying to summarize the gotchas to Nexus and Jenkins in a CI/CD environment.

Gotcha 1 : Enterprise environment limited access

Suddenly what I find is I am having limited access in the Jenkins environment. Below are the limitations

1.No access to Jenkins box (Linux terminal) or the nexus box

2. All the configuration settings.xml or other need to be managed by Configfile Provider https://wiki.jenkins.io/display/JENKINS/Config+File+Provider+Plugin

The installation instruction is straight forward once installed Manage Jenkins->Manage files

Create a Global maven settings.XML and three entries

1.Sanp Shot repo (For storing the generated artifact SNAPSHOTS)

2. Release repo (For string the release artifacts)

3. Group repo (Combination of Snapshot and group) — — Nexus refers its dependencies from here .Look into this for the configuration https://blog.sonatype.com/using-nexus-3-as-your-repository-part-1-maven-artifacts

maven seetings.xml in file configuration manager Jenkins

Below is my setting.xml you may find the full project in https://github.com/bappa0125/nexus-artifact-upload

<?xml version=”1.0" encoding=”UTF-8"?><settings xmlns=”http://maven.apache.org/SETTINGS/1.0.0"xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation=”http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"><localRepository>/root/.m2/repository</localRepository><servers><server><id>dcpp_release</id></server><server><id>dcpp_snapshot</id></server></servers><mirrors><mirror><id>maven-group</id><name>central</name><url>https://alm.accenture.com/nexus/repository/Newspage_Replatform_Stage_2_Group/</url><mirrorOf>*</mirrorOf></mirror><mirror><id>MavenCentral</id><url>https://repo.maven.apache.org/maven2</url><mirrorOf>central</mirrorOf></mirror></mirrors><profiles><profile><id>ADOP_Nexus</id><repositories><repository><snapshots><updatePolicy>always</updatePolicy><enabled>false</enabled></snapshots><id>dcpp_release</id><name>libs-release</name><url>https://alm.XXXX.com/nexus/repository/xxxxxx_2_Release/</url></repository><repository><snapshots><updatePolicy>always</updatePolicy></snapshots><id>dcpp_snapshot</id><name>libs-snapshot</name><url>https://alm.xxxx.com/nexus/repository/xxxxxxx_2_Snapshot/</url></repository></repositories><pluginRepositories><pluginRepository><snapshots><enabled>false</enabled></snapshots><id>dcpp_release</id><name>libs-release</name><url>https://alm.xxxxxx.com/nexus/repository/xxxxxx_Release/</url></pluginRepository><pluginRepository><snapshots /><id>dcpp_snapshot</id><name>libs-snapshot</name><url>https://alm.xxxxx.com/nexus/repository/xxxxxxxx_Snapshot/</url></pluginRepository></pluginRepositories></profile></profiles><activeProfiles><activeProfile>ADOP_Nexus</activeProfile></activeProfiles></settings>

When you put it into the Jenkins job the main configuration has below parts

  1. git section where you mention url

Check from the first section this was the name of the file . this is actually settings.xml , you can name it anything. Note: For managed plugin setting this file is not in the default /root/.m2 or user.home/.m location you may put it in few ways

1. Write shell script command line cp $(WORKSPACE)/MyGlobalSettings /root/m2/settings.xml (or where ever your maven repo is present)

2. Create an alias alias mvn=’mvn — global-settings ${WORKSPACE}/MyGlobalSettings’

3. Or by using -s flag to mvn command , ex mvn clean deploy -s ${WORKSPACE}/MyGlobalSettings

To deploy an artifact in Nexus

Use mvn clean deploy -s ${WORKSPACE}/MyGlobalSettings

Below is the sample pom file

<repositories><!--                      <repository><id>maven-public</id><url>http://nexus-coe.magellancloud.com/repository/maven-public/</url></repository>--><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/libs-milestone</url><snapshots><enabled>false</enabled></snapshots></repository></repositories><distributionManagement><snapshotRepository><id>dcpp_snapshot</id><url>https://alm.xxxxxx.com/nexus/repository/xxxxx_Snapshot/</url></snapshotRepository><repository><id>dcpp_release</id><url>https://alm.xxxxxx.com/nexus/repository/xxxxxx_Release/</url></repository></distributionManagement>

you may find the full pom from git

The distribution management should have the same server id and url present as mention in settings.xml (change the urls as per ur nexus repo address

If all goes will you can see your artifacts deployed in the nexus repo

nexus artifact is uploaded

But unless you are very lucky you will get in to 400 or 401 errors

for 400 below are the reason which are very well mentioned in stack over flow https://stackoverflow.com/questions/18649486/error-when-deploying-an-artifact-in-nexus

· user credentials are wrong

· url to server is wrong

· user does not have access to the deployment repository

· user does not have access to the specific repository target

· artifact is already deployed with that version if it is a release (not -SNAPSHOT version) — super crucial

the repository is not suitable for deployment of the respective artifact (e.g. release repo for snapshot version, proxy repo or group instead of a hosted repository)

error 400 comes for incorrect password, using email id (you should use user id of nexus) , unwanted spaces e.t.c

Next I will write about how to create mirrors so that we can get the private jars from nexus not from maven central…until then happy DevOpsing..

--

--