How To Configure Maven In Jenkins

In this recipe, we’ll walk through how to configure maven in Jenkins. To configure maven in Jenkins first we need maven so install maven in your Linux machine.

Before going to install i will create one directory and i will download maven into that directory.

mkdir -p /opt/maven

Here i created a directory called maven in /opt/ and now i will download maven into this directory
cd /opt/maven

Configure Maven In Jenkins

Download Maven:

By using wget command we can download maven from official Apache maven website. If you get error like wget command not found install wget with below commands.

yum    install    wget   -y 
wget      http://mirrors.estointernet.in/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz
tar     -xzf      apache-maven-3.6.0-bin.tar.gz

I downloaded maven  and extracted by using tar command in /opt/maven directory. by using tar -xzf command we can extract tar.gz files


[root@ip-10-0-0-25 maven]# ls
apache-maven-3.6.0      apache-maven-3.6.0-bin.tar.gz
cd apache-maven-3.6.0

[root@ip-10-0-0-25 apache-maven-3.6.0]# pwd
/opt/maven/apache-maven-3.6.0

copy this path we use this path in Jenkins global tool configuration

Configuring Maven In Jenkins

in Jenkins go to manage Jenkins and go to  Global Tool Configuration

How To Configure Maven In Jenkins

Here you can see maven option enter any name. Here i am giving name as  maven-path and for  MAVEN_HOME give /opt/maven/apache-maven-3.6.0

and save it. This is path where we have downloaded the maven.

Choose Maven Version:

When you are configuring job in the build section.  Go to invoke top level maven targets and  choose maven version as maven-path. Here in the right side you can see a drop down option, select your maven version. It will show maven versions which we have configured in global tool configuration. So i selected maven version as maven-path.

Configuring Maven In Jenkins

 In the goals section you can give your maven goals. That’s it we have successfully configured maven Jenkins.

If you miss any steps when you are configuring the maven. You will get errors and your job will fail.

So follow exact steps whatever i mentioned in the above section.

 

  • How To Configure Maven In Jenkins
  • maven configuration in Jenkins