0

I am using the image jenkins/ssh-slave as base in my dockerfile. I would like to install a specific maven version and configure the settings. But it does not work, it is not picking the settings to download the artifactories from my nexus. Moreover, I dont know who to specify the maven version :(

You can see my dockerfile below. I have tried to install Maven typing maven:3.5.6 but it says it cannot find that. And also I copy my settings but maven does not go to my nexus to download the dependencies (the settings.xml works in local)

FROM jenkins/ssh-slave

# Install selected extensions and other stuff
RUN apt-get update && apt-get -y --no-install-recommends install && apt-get clean   

# Install maven 
RUN apt-get install -y maven

COPY ./settings.xml /usr/share/maven/conf/settings.xml

Can anyone help? Thank you very much in advance.

  • Are you running any maven command like mvn clean install or mvn clean package ? – Sambit Sep 11 '19 at 07:07
  • Yes, I run ```mvn clean install``` and at that point it tries to download the dependencies, getting an error because it cannot download the custom dependencies that are only in our nexus repo. – Fany Castro Vizoso Sep 11 '19 at 12:05

2 Answers2

2
FROM jenkins/ssh-slave

# Install selected extensions and other stuff
RUN apt-get update && apt-get -y --no-install-recommends install && apt-get clean
RUN apt-get install -y curl 

ARG MAVEN_VERSION=3.6.2
ARG USER_HOME_DIR="/usr/jenkins"
ARG SHA=d941423d115cd021514bfd06c453658b1b3e39e6240969caf4315ab7119a77299713f14b620fb2571a264f8dff2473d8af3cb47b05acf0036fc2553199a5c1ee
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries

RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
  && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
  && echo "${SHA}  /tmp/apache-maven.tar.gz" | sha512sum -c - \
  && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
  && rm -f /tmp/apache-maven.tar.gz \
  && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn

ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"

RUN chown -R jenkins:jenkins /home/jenkins &&  chmod -R 777 /home/jenkins
COPY --chown=jenkins:jenkins ./settings.xml /home/jenkins/.m2/settings.xml
0

As per your question,

I would like to install a specific maven version and configure the settings.

I would suggest you to use Maven Wrapper (mvnw) instead of mvn command. This will give you flexibility to build an application without pre installing Maven in a vm or a system. Since you are using Docker and somewhere you are using mvn clean install command, I would suggest you to use mvnw clean install.

There is a difference between mvn clean install and mvnw clean install. If you want a specific version of maven, you can also set in maven-wrapper.properties file.

I provide below few links so that it will be useful for you.

https://www.baeldung.com/maven-wrapper

What is the purpose of mvnw and mvnw.cmd files?

If want a very simple example on maven wrapper, refer below the github link. https://github.com/debjava/maven-wrapper-example

Sambit
  • 7,625
  • 7
  • 34
  • 65
  • Thanks @Sambit, but I am trying to use containers slaves in jenkins. Currently the pipeline is working with the maven wrapper, but I would like to learn how to build a container with ssh, open jdk and maven so that I can use it as a slave in jenkins. – Fany Castro Vizoso Sep 11 '19 at 14:37