Jenkins Slave can't read settings.xml

I have created a jenkins slave image for Docker, which I want to use to build all of my Java projects, however, I can’t work out how to reference the .m2/settings.xml file to tell it where to pull from.

My Dockerfile is:

  • Docker swarm mode running Hazelcast cluster
  • How to override default docker container command or revert to previous container state?
  • ldapadd gives “no global superior knowledge” on default config
  • AWS EB Deploy shows missing Dockerrun.aws.json after deploying
  • Automatically run command inside docker container after starting up + volume mount
  • Clean Docker /var/lib/docker/devicemapper
  • FROM openjdk:8
    MAINTAINER Chris Hudson <chudson@amelco.co.uk>
    
    RUN apt-get -qqy update && \
        apt-get -y install openssh-server sudo
    
    RUN useradd -m -u 1000 -s /bin/bash jenkins && \
        mkdir -p /home/jenkins/.ssh && \
        mkdir -p /home/jenkins/.m2 && \
        echo jenkins:jenkins | chpasswd && \
        mkdir -p /etc/sudoers.d/ && \
        echo "jenkins ALL=(root) NOPASSWD: ALL" > /etc/sudoers.d/jenkins && \
        chmod 440 /etc/sudoers.d/jenkins
    
    COPY id_rsa.pub /home/jenkins/.ssh/authorized_keys
    COPY settings.xml /home/jenkins/.m2/
    
    RUN chown -R jenkins:jenkins /home/jenkins
    
    RUN mkdir -p /var/run/sshd
    
    EXPOSE 22
    CMD ["/usr/sbin/sshd", "-D"]
    

    But when I run the build, it attempts to pull from maven central, and not our local Artifactory instance, which is configured in the settings file.

    This works when I run it on Jenkins Master, but I want to offload the builds to the slaves, but I can’t work out how to configure Maven correctly.

  • Running multiple time the same docker image
  • Monit not clearing the pid file and restarting a process when the process becomes a zombie
  • Kubernetes - ReplicationController and Persistent Disks
  • How to pull layers one by one in Docker?
  • disk I/O error when using Sqlite3 and SqlAlchemy in docker
  • Unable to see Selenium Grid running when viewed from browser
  • One Solution collect form web for “Jenkins Slave can't read settings.xml”

    I think that your workspace is mounted from the slave. and it’s not read the .m2 from your container

    you can try use his plugin – https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin to create the settings.xml and configure your MVN build step to use it.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.