Install & configure the Maven build tool on Jenkins

Muhammad Rashid
2 min readNov 23, 2022
https://www.youtube.com/@CodeWithMuh

Maven is a code build tool used to convert your code to an artifact. this is a widely used plugin to build a continuous integration

Prerequisites

  1. Jenkins server
hostname  jenkins
sudo su -
cd /opt
ls -ltr

Install Maven on Jenkins

  1. Download maven packages https://maven.apache.org/download.cgi onto Jenkins server. In this case, I am using /opt/maven as my installation directory
sudo tar -xvzf apache-maven-3.8.6-bin.tar.gz
sudo mv apache-maven-3.8.6 maven
cd maven
  1. Setup M2_HOME and M2 paths in .bash_profile of the user and add these to the path variable
[root@jenkins ~]#  vi ~/.bash_profile
M2_HOME=/opt/maven
M2=$M2_HOME/bin
echo $M2
exit
sudo su -
echo $M2
echo $M2_HOME
[root@jenkins ~]# vi ~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.17.0.8–2.el9_0.x86_64
M2_HOME=/opt/maven
M2=$M2_HOME/bin
PATH=$PATH:$JAVA_HOME:$HOME/bin:$M2:$M2_HOME

export PATH
exit
sudo su -

Checkpoint

  1. logoff and login to check maven version
mvn - version

So far we have completed the installation of the maven software to support the maven plugin on the Jenkins console. Let’s jump onto Jenkins to complete the remaining steps.

Setup maven on Jenkins console

  1. Install maven plugin without restart
  • Manage Jenkins > Jenkins Plugins > available > Maven Invoker
  • Manage Jenkins > Jenkins Plugins > available > Maven Integration

2. Configure the maven path

  • Manage Jenkins > Global Tool Configuration > Maven

Done.

If you Want to Learn Python, You can watch my ultimate Python Course on My Youtube Channel.

You can join there as well to share your Queries and suggestions. Facebook Facebook Group: https://web.facebook.com/groups/890525732087988/?mibextid=HsNCOg

You can Also Follow Me on My Social Media Platforms:

  1. Facebook
  2. Youtube
  3. Twitter & Instagram
  4. GitHub & Replit
  5. Upwork

Thank You for reading!

--

--