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 for mac - Not able to connect to a mongo replica set running on host from inside the container
  • docker - multiple projects on one Dockerfile and docker-compose.yml
  • I've started my Docker container but it is not staying up
  • Docker-compose: nginx does not work with django and gunicorn
  • Docker - how to send input to a program via the API
  • docker—run nginx not allways working
  • 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.

  • 502 Bad Gateway Error with Docker Swarm service
  • JMX - remote management into docker-compose container - Failed to retrieve RMIServer stub
  • cannot connect on SQLserver with Docker on mac
  • Docker Datacenter: Error x509 certificate signed by unknown authority UCP 2.0.0 and DTR 2.1.0 with external certificates
  • Passing Different Arguments When Running Docker Image Multiple Times
  • Can I suspend and then resume Docker container?
  • 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.