Abhilash D K
Abhilash D K

Reputation: 1309

Install Maven in jenkins/blueocean docker container

I have started learning jenkins by using jenkinsci/blueocean docker image. Turns out this image does not have maven installed. I followed Maven Installation on Jenkins Docker Container link to install maven from a .gz file. It did not work.

Can anybody tell me how to install maven inside jenkinsci/blueocean container.

Thanks in advance.

Upvotes: 0

Views: 3363

Answers (2)

B.K
B.K

Reputation: 897

The jenkins/blueocean image is based on Alpine Linux. You can check this by running

cat /etc/*-release

inside the container.

To install packages on Alpine Linux you will need to use the apk package manager. For example:

apk add --no-cache package_name

However, to successfully run this you need to access the container as root. This can be achieved by running the command below:

docker exec --user root -it container_ID bash

You can then install maven in the jenkins/blueocean container by running the command:

apk add --no-cache maven

Upvotes: 1

Naymesh Mistry
Naymesh Mistry

Reputation: 946

Jenkins Blueocean docker image is based on Alpine Linux (Found this by running cat /etc/*-release from inside the image via Portainer).

Alpine uses apk as the package manager/installer. So

  • Console login into the container (shell access). Again, I used Portainer's Console connect feature for this.
  • Ran apk add maven to install maven. This worked and Jenkins step in workflow script sh mvn clean install could execute successfully.

EDIT The alternative and much better way would be to use a separate maven docker container as Jenkins agent as suggested in the tutorial documentation here:

pipeline {
    agent {
        docker {
            image 'maven:3-alpine' 
            args '-v /root/.m2:/root/.m2' 
        }
    }
    stages {
        stage('Build') { 
            steps {
                sh 'mvn -B -DskipTests clean package' 
            }
        }
    }
}

Upvotes: 2

Related Questions