Maven serves as a crucial code build tool, transforming your code into an artifact. It’s widely utilized in continuous integration processes.
Prerequisites
Ensure you have:
- A Jenkins server.
Install Maven on Jenkins
To install Maven on your Jenkins server, follow these steps:
- Download Maven packages from https://maven.apache.org/download.cgi onto your Jenkins server. Here, I’ll use /opt/maven as the installation directory. Link: https://maven.apache.org/download.cgi
# Create maven directory under /opt mkdir /opt/maven cd /opt/maven # Download maven version 3.6.0 wget http://mirrors.estointernet.in/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz tar -xvzf apache-maven-3.6.1-bin.tar.gz
- Set up M2_HOME and M2 paths in .bash_profile of the user and add these to the path variable.
vi ~/.bash_profile M2_HOME=/opt/maven/apache-maven-3.6.1 M2=$M2_HOME/bin PATH=<Existing_PATH>:$M2_HOME:$M2
Checkpoint
Log off and log in to check the Maven version.
mvn --version
This completes the Maven software installation to support the Maven plugin on the Jenkins console. Let’s proceed to Jenkins to finish the remaining steps.
Setup Maven on Jenkins console
Follow these steps to configure Maven on the Jenkins console:
- Install the Maven plugin without requiring a restart:
- Navigate to
Manage Jenkins
>Jenkins Plugins
>Available
>Maven Invoker
. - Navigate to
Manage Jenkins
>Jenkins Plugins
>Available
>Maven Integration
.
- Configure the Maven path:
- Access
Manage Jenkins
>Global Tool Configuration
>Maven
.