Piduna
Piduna

Reputation: 637

How to add settings.xml to build process of Jenkins to docker image

I have Jenkinsfile in my repository:

pipeline {
    agent {label 'slavedev'}

    stages {
        stage('Build') {
            agent {
                docker {
                   image 'myimage:latest'
                   }
            }
            steps {
                sh 'mvn -version'

            }
        }
    }
}

Dockerfile of myimage:

ROM maven:latest

COPY settings.xml /root/.m2/

When i am trying to start manually this image via docker run -it myimage:latest /bin/bash, i see:

root@9a963055c12f:/tmp# ls -lta /root/.m2/
total 12
-rw-r--r-- 1 root root  129 Jul 21 18:53 copy_reference_file.log
drwxr-xr-x 1 root root   82 Jul 21 18:53 .
-rw-r--r-- 1 root root  327 Jul 21 18:53 settings-docker.xml
drwxr-xr-x 2 root root    6 Jul 21 18:53 repository
drwx------ 1 root root   17 Jul 21 17:58 ..
-rw-rw-r-- 1 root root 2897 Jul 21 17:57 settings.xml

How you see, we have settings.xml in .m2. But, when i am trying to execute Jenkins-job with downloading of sources, i see, that:

     [exec] [DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml
     [exec] [DEBUG] Reading user settings from ?/.m2/settings.xml

And also, i don't see, what in Docker-container. I see only list of my sources.

drwxrwxr-x 5 jenkins jenkins    41 Jul 21 17:52 src
-rw-rw-r-- 1 jenkins jenkins  3212 Jul 21 17:52 build.xml
-rw-rw-r-- 1 jenkins jenkins 32014 Jul 21 17:52 pom.xml

And job, that works locally, does not work in the container. Really, i tried everything, please help! I played with everything, I don't sleep two nights, but i am really can't find, how to run this!
setting.xml file with private repository and credentials to this repository.

Upvotes: 0

Views: 5601

Answers (1)

yong
yong

Reputation: 13712

You can specify settings.xml by option -s

sh 'mvn -s /root/.m2/settings.xml -version'

You check jenkins run the container with which user from the build log. If it's not run with root user, Maven won't use the settings.xml from /root/.m2.

Upvotes: 1

Related Questions