简体   繁体   English

如何添加settings.xml以将Jenkins的过程构建到Docker映像

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

I have Jenkinsfile in my repository: 我的存储库中有Jenkinsfile

pipeline {
    agent {label 'slavedev'}

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

            }
        }
    }
}

Dockerfile of myimage : Dockerfilemyimage

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: 当我尝试通过docker run -it myimage:latest /bin/bash手动启动此映像时,我看到:

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 . .m2 ,我们在.m2settings.xml But, when i am trying to execute Jenkins-job with downloading of sources, i see, that: 但是,当我尝试通过下载源代码执行Jenkins-job时,我发现:

     [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. 而且,我也看不到Docker容器中的内容。 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. 带有私有存储库和此存储库凭证的setting.xml文件。

You can specify settings.xml by option -s 您可以通过选项-s指定settings.xml

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

You check jenkins run the container with which user from the build log. 您检查jenkins从构建日志中运行与用户一起使用的容器。 If it's not run with root user, Maven won't use the settings.xml from /root/.m2 . 如果不是以root用户运行,则Maven将不会使用/root/.m2的settings.xml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM