Java – How do I use Jenkins credentials when running ‘mvn deploy’?

How do I use Jenkins credentials when running ‘mvn deploy’?… here is a solution to the problem.

How do I use Jenkins credentials when running ‘mvn deploy’?

I have a Maven project and want to build it with mvn clean deploy to deploy the built artifact into a nexus repository.

Access data (username and password) for this repository is stored in Jenkins credentials.

I want to call mvn deploy in Jenkins to read the credentials for that Nexus repository from Jenkins (not hard-coded in settings.xml).

What should I do if I can’t access the settings.xml on the Jenkins server?

Update 1:

I created an entry in Profile Management (JENKINS_URL/configfiles/index) with the following data:

Type: Maven settings.xml

Replace All: Yes

Server ID: myServer

Credentials: Credentials for the Nexus repository


<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="" 


Edit configuration file

myServer is also used for pom.xml of the artifact I’m building


In the configuration of the job, I included the settings shown below. Nexus settings.xml is a configuration in Config File Management.

Jenkins build configuration

But it doesn’t work – I get a “forbidden” error when the build tries to deploy the artifact to Nexus.

Update 2: When I run mvn -X deploy locally (stored in my local settings.xml with the same credentials as in Jenkins, I see the following output:

[DEBUG] Failed to decrypt password for server XXX release repository: org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: /XXXXXXXXXXXXXXX/.m2/settings-security.xml (No such file or directory)
org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException: /XXXXXXXXXXXXXXX/.m2/settings-security.xml (No such file or directory)
    at org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher.decrypt(
    at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt(
    at org.apache.maven.settings.crypto.DefaultSettingsDecrypter.decrypt(
    at org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory.newRepositorySession(

However, the password in settings.xml is not encrypted at all:

<settings xmlns=""

I found a report of a similar error here


You can use the Jenkins config-file-provider plugin (link: Create one or more Maven settings.xml files.

NOTE: Really this helps also if you need differents settings.xml for
different projects.

Then in the maven deployment step of the Jenkins project, you can choose to point to one of the defined settings.xml files (instead of pointing to the generic Jenkins server/.m2/settings.xml).

Related Problems and Solutions