Configure the remote Maven repository in Jenkins project jobs

Article ID:219872588
2 minute readKnowledge base

Issue

I have maven installed and configured my Jenkins Enterprise controller. I can build a project using "mvn install" without any problem. When I try to build a project, it results in this error:

ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Failure to find com.acme.project.platform:app-one:pom:2016.5.2 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced...

Hence, Jenkins is attempting to connect to the global maven.apache.org rather than my local repository.

Items to Consider:

The local maven repository defaults to ~/.m2. So if you did mvn install on the local machine as a different user to the one Jenkins runs as this won’t work.

Also, if you are running your job on an agent, it’s possible that the Jenkins job won’t be looking at the local M2 repo. This depends on what sort of job you are using (Maven Project vs Freestyle Project)

Environment

  • CloudBees Jenkins Enterprise - Managed controller (CJEMM)

  • CloudBees Jenkins Enterprise- Operations Center (CJEOC)

  • CloudBees Jenkins Team (CJT)

  • CloudBees Jenkins Platform - Client controller (CJPCM)

  • CloudBees Jenkins Platform - Operations Center (CJPOC)

Resolution

Solution 1:

Configure the settings.xml file globally (via Jenkins > Mange Jenkins > Configure System - Maven Configuration).

Solution 2:

If you need to define one Maven configuration per job (for Maven projects) you should use the Config File Provider Plugin This is particularly useful for configuring multiple Maven configurations, such as one per environment (e.g. Dev, QA, etc)

If you configure the default settings after the creation of the job, the job configuration wont be automatically updated. The default settings as configured in "configure system" are used only at creation time such as this:

For a freestyle job…​

maven settings freestyleproject

For a maven job…​

maven settings mavenproject

Hence, if you change the default settings they aren’t updated in existing jobs. The update needs to be applied manually (or with a script) in existing jobs.

If you create a new job after having registered your configuration file in the Config File Provider Plugin and configured it as default in Configure System, it should pick up the Maven repository settings without issue.