Daniel Calderon Mori
Daniel Calderon Mori

Reputation: 5776

Jenkins can't find maven setting.xml file outside Jenkins Home

I have Jenkins running on CentOS server and I'm trying to set up a job that runs mvn clean install on a git project. Since I want to use a global maven repository for my whole server, I'm setting up my project to run maven using a setting file in a path outside Jenkins home:

enter image description here

When running the build, Jenkins can't find that settings.xml file:

...
[workspace] $ /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.0.4/bin/mvn -f firma-digital-service/pom.xml -s /home/dcalderon/.m2/repository/settings.xml -X clean package
Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.0.4
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-123.4.2.el7.x86_64", arch: "amd64", family: "unix"
[INFO] Error stacktraces are turned on.
[ERROR] Error executing Maven.
java.io.FileNotFoundException: The specified user settings file does not exist: /home/dcalderon/.m2/repository/settings.xml
at org.apache.maven.cli.MavenCli.settings(MavenCli.java:681)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:193)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE

When running the exact same commands Jenkins runs via command line everything works correctly which show that the file does exist in the server. What am I doing wrong? Is it an issue regarding user restrictions?

Upvotes: 4

Views: 15191

Answers (4)

Prakshal
Prakshal

Reputation: 31

I am using the scripted pipeline and in my case added/updated the settings.xml file located at /var/lib/jenkins/.m2/ folder.

Upvotes: 0

parishodak
parishodak

Reputation: 4666

As an extension answer, when there are no specific changes to configuration, we can also say to use default settings for maven in the Jenkins configuration as mentioned below:

Settings file: Use default maven settings Global Settings file: Use default maven global settings

Maven Settings in Jenkins Job Configuration Page

Upvotes: 3

yorammi
yorammi

Reputation: 6458

Jenkins runs as jenkins user so it can't see a file located in /home/dcalderon folder

Upvotes: 0

Mor Lajb
Mor Lajb

Reputation: 2636

you can use this plugin - https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin to manage the settings.xml.

just provide the relevant file to your project using this plugin.

Thanks , Mor

Upvotes: 0

Related Questions