How to configure Nexus from Jenkins with Maven

Kishen Steve Simbhoedatpanday
2 min readDec 10, 2021

Today I’ve been googling my hands off to find a way to connect to Nexus from Jenkins using Maven.

Since this was a though journey for me, I decided to log all my findings in this blogpost. Hopefully this blogpost will help you connect all the dots.

In this case I’ve used the Jenkins Config File Management plugin to make the roundtrip work.

1: Create your Nexus credential in Jenkins.
Go to <jenkins-url>/credentials/store/system/domain/_/
Click “Add Credentials” on the left and enter your Nexus credentials (with User Token)

2: Create a new Config File configuration to setup your maven settings.
Go to the job that needs the Nexus repo and click Config Files on the left.
(Or go to <jenkins-url>/job/<jobname>/configfiles/)
Click “Add new config” on the left.
Select “Global Maven settings.xml” en fill in the ID and content.

Make sure you tick the Replace All checkbox.
Click Add and enter the same ID of the mirror you’ve added in the settings.xml file. In this example it should be ‘nexus’.
Then make sure you select the Jenkins credentials you’ve created in step 1 in the Server Credentials section.
The Config File configurator plugin will make sure that the credentials are added when you start using this configuration.

3: Use the Jenkinsfile configFileProvider to make use of the settings.xml.

The configFileProvider will pass the configuration from the Maven settings.xml to the shell script that runs maven via the MAVEN_SETTINGS local variable.

Happy building!

--

--

Kishen Steve Simbhoedatpanday

Software Test Developer. Podcast host @codeklets. Living room DJ. Married to @jufsantweet & father of Jayden & Mila.