What is causing use of wrong settings.xml in Maven

987 views
Skip to first unread message

Lee Meador

unread,
May 30, 2019, 3:52:02 PM5/30/19
to Jenkins
I'm pretty sure some Jenkins plugin is causing this. Using 2.164 :

I have a scripted pipeline build and the maven call is of this form:

withMaven(..., mavenSettingsFilePath: settings1.xml, ...) {
    sh 'mvn -X --settings settings1.xml clean package'
}

(If I leave out the --settings, it does exactly the same thing)

The file settings1.xml has this in it to tell where to get maven dependencies. I printed it in the console log with a "sh 'cat settings1.xml' "

14:08:59     <mirrors>
14:08:59         <mirror>
14:08:59             <id>nexus</id>
14:08:59             <mirrorOf>!artifactory-snapshots,*</mirrorOf>
14:08:59             <name>artifactory mirrored central repos.</name>
14:08:59             <url>https://example.com/artifactory/OT-public/</url>
14:08:59         </mirror>
14:08:59     </mirrors>

These messages appear in the log (using -X). I've snipped the workspace path out AND verified that withMaven seems to have copied my settings1.xml file to a working folder.

14:09:00 [DEBUG] Reading global settings from /usr/local/apache-maven-3.3.9/conf/settings.xml
14:09:00 [DEBUG] Reading user settings from <..workspace..>@tmp/withMaven430960bf/settings.xml
<snip>
14:09:00 [INFO] Scanning for projects...
14:09:00 [DEBUG] Using transporter WagonTransporter with priority -1.0 for https://example.com/artifactory/maven-public/
14:09:00 [DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://example.com/artifactory/maven-public/ with username=, password=***
14:09:00 [INFO] Downloading: https://example.com/artifactory/maven-public/org/springframework/boot/spring-boot-starter-parent/2.0.2.RELEASE/spring-boot-starter-parent-2.0.2.RELEASE.pom
All the logs show it loading things from "maven-public" which, you will note, is not the repository in my settings1.xml file.

Based on the message about the WagonTransporter, can someone suggest a plugin that may be overriding my settings1.xml configurations?

Thanks

-- Lee Meador
Sent from gmail. My real email address is lee AT leemeador.com

Cyrille Le Clerc

unread,
May 30, 2019, 5:31:09 PM5/30/19
to Jenkins Users
Hello Lee,

Thank you for using the Pipeline Maven integration.

First, can I recommend you to not define simultaneously the settings file as a "withMaven" parameter and in the "mvn" command invocation.
If it's the same file as your example suggests it, you don't need to specify it in the "mvn" command. 
If you need to compose two Maven settings file, you could use a "global settings file" and a "local settings file" to avoid any conflict?

Second, can you explain us why you have to pass a settings file path? is it because dev team can add a Maven settings file in their application code repository? is it because you copy this Maven settings file on the build agents? I would greatly recommend to manage all the Maven settings files through the Jenkins Configuration File Provider. You can define Maven settings file globally or at the folder level.

Third, to better understand the effective Maven settings, can you invoke "mvn ... help:effective-settings" in the "withMaven" block not forgetting to pass the same parameters as what you pass in your "mvn clean package"? See https://maven.apache.org/plugins/maven-help-plugin/effective-settings-mojo.html

Last but not least, instead of specifying the Maven settings file in the "withMaven" step (e.g. "withMaven(mavenSettingsConfig: 'some-maven-settings')"), you can define default Maven settings at the global level or at the folder level. Please see https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin#PipelineMavenPlugin-MavenSettingsSupport

Cyrille

Lee Meador

unread,
Jun 3, 2019, 7:03:39 PM6/3/19
to Jenkins
Cyrille - thank you for your answer.

We have shared code that builds the settings.xml file and allows pointing to one of several different Nexuses and Artifactories plus the shared code injects appropriate credentials into the settings.xml without exposing the passwords. We couldn't figure out any other way to meet those requirements.

You will note that I said I had tried it with just withMaven() and without the --settings on the command line and said it made no difference. Perhaps it would have been less confusing if I erased it in the question.

We resolved the issue when we found that there was a global settings.xml file on the Jenkins build agents that had a mirrorOf clause for 'central' with the URL for maven-public repository. What I was unaware of was that a mirrorOf * would not override a mirrorOf central when the latter was in the global settings.xml. I added a mirrorOf central to my generated settings.xml and that overrode the one in the global settings.xml. Fixed!

I suppose that is in the maven docs somewhere but I had never seen it and learned it.

You are correct about the use of help:effective-settings which I happened to find and led to the successful solution.

Finally, I do prefer to put things like default configuration of withMaven's settings.xml into shared code instead of clicking around in the folders. I lose track of things configured in the Jenkins folder structures. The only way I have found to search for places that have set some property in the manual configuration is to go to the server and do a "find .../jobs -name 'config.xm*' grep 'something'" (that's not a complete bash command but grepping in all the config files will do that sort of search.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/d885a02f-09ff-4842-9df8-753133ef941a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Reply all
Reply to author
Forward
0 new messages