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?
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.
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
Here is the simplest way to install maven into docker:
Connect to docker with root privilages
sudo docker exec -u root -t -i [container-id] bash
update and install maven
apt-get update & apt-get install
That's it.
Works file for me
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && apt-get install -y maven
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With