Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extend jenkins image to install maven

I'm using the jenkins/jenkins:lts image at the moment. It runs fine and does everything I want to expect one thing. I want it to run Maven goals in the build steps. The problem is that there is not maven installed in the jenkins container environment.

So I want to extend the mentioned image to run an apt-get install maven.

My solution:

FROM "jenkins/jenkins:lts
USER root
RUN /bin/bash -c "apt-get install maven"

Will this be enough? I assume that all RUN and ENTRYPOINT steps of the jenkins image will run by itself and I do not need to re-execute them in my Dockerfile right?

like image 320
xetra11 Avatar asked Sep 05 '17 10:09

xetra11


People also ask

How do you integrate Jenkins with Maven?

In the Jenkins dashboard (Home screen), click Manage Jenkins from the left-hand side menu. Then, click on 'Configure System' from the right hand side. In the Configure system screen, scroll down till you see the Maven section and then click on the 'Add Maven' button.


4 Answers

According to the documentation, this would be in your dockerfile

FROM jenkins/jenkins:lts
# if we want to install via apt
USER root
RUN apt-get update && apt-get install -y maven
# drop back to the regular jenkins user - good practice
USER jenkins

Assuming your docker file is in your current directory this is how you would build the image and install in your local docker repo

docker build -t jenkins-maven .

For more information

https://github.com/jenkinsci/docker

After installing maven this way, the mvn version will probably be older than what you need. When I ran this, it was Apache Maven 3.3.9

like image 148
pitchblack408 Avatar answered Oct 19 '22 07:10

pitchblack408


Here is the simplest way to install maven into docker:

  1. Connect to docker with root privilages

    sudo docker exec -u root -t -i [container-id] bash

  2. update and install maven

    apt-get update & apt-get install

That's it.

like image 41
Mehmet Mustafa Demir Avatar answered Oct 19 '22 06:10

Mehmet Mustafa Demir


Works file for me

FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt-get install -y maven
like image 28
Arthur Silva Avatar answered Oct 19 '22 06:10

Arthur Silva


you need to update package cache before install, and don't miss -y for apt-get install.

FROM jenkins/jenkins:lts
RUN apt-get update && apt-get install -y maven
like image 37
Bukharov Sergey Avatar answered Oct 19 '22 07:10

Bukharov Sergey