0
votes

I am creating Jenkins Slave on the fly configuring it on AWS with Spot Instances. In the global tool configuration, I have set to use my own "settings.xml" for the master is working perfectly.

But when the server start slaves (without maven installed) it auto install maven (set in the Jenkins file to install this tool) but without putting any settings.xml

*I know I can copy the setting.xml directly from the server but for me looks like it is not the appropriate way to do it. * I already did mvn -X in order to see find the folder for the settings but this is not used.

Added one small slice of the jenkinsfile

pipeline {

tools{
    maven 'maven default'
}
agent  any

stages {
    stage('Maven build') {
        steps {
           sh 'mvn clean install'                
            }
        }
    }
}
1
Where have you configured the settings.xml in Jenkins? Using the config file provider plugin for that ? - khmarbaise
Yes, it is already configured and working for the master - Guel135
If I correctly understand than your job/pipeline configurations are wrong cause if you use correctly the config-file-provider in your job/pipelines this will be handled by Jenkins ...the question is how your job/pipeline code looks like.. - khmarbaise
I have added my jenkinsfile. And when it run in the master node are working perfectly - Guel135
That's what I expected...which can't be working on nodes... - khmarbaise

1 Answers

3
votes

You have to use withMaven() in the Pipeline code..which has to look like this:

withMaven(jdk: jdkName, maven: MavenInGlobalToolsName, mavenSettingsConfig: 'IdInConfigFileProvided', mavenLocalRepo:".repository") {
  sh "mvn clean verify"
}

The IdInConfigFileProvided is the important part which makes the reference to the config file provider plugin...

The other solution could be to use the config file provider directly in Jenkins file:

configFileProvider(
    [configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
    sh 'mvn -s $MAVEN_SETTINGS clean package'
}

But this solution will not handle the support global tools support for Maven itself. So I would suggest to prefer the withMaven() solution.