How to Create a New Maven Job in Jenkins

We are going to check out how to create a new Maven job in Jenkins when you already have your code up and running on your local.

So, you already have a project with you and you wish to be able to run it through Jenkins, so that everyone in your team could run it from one prime location, without having to, you know, install Java, Maven or any other software on their system. How cool does that sound?

To be able to do that you need to configure Jenkins to give an end user the ability to simply build with one click, without having to get into the “what and how”, the technicalities of the project. All you need to do is some minor tweaking and you can have your project up and running in no time.

jenkins build meme for how to create a new Maven job in Jenkins

Here’s a step by step tutorial on how to create a new Maven job in Jenkins:

How to Create a New Maven Job in Jenkins

Step 1: Open Jenkins and navigate to your box.

Click on New Item in Jenkins box

Step 2: Click on New Item. It will navigate you to the following screen:

Enter an Item Name and select Maven Project

Step 3: Click on Maven Project and provide a name for your project.

Step 4: Once done, click on Ok button.

Enter Name and then click on Ok

The next screen will require you to configure your build.

NOTE: If your test case requires the use of some parameters, you can check out how to add a parameter in Jenkins.

If not, continue.

Step 5: Navigate down till you find the label of JDK. Select JDK – 1.8.

JDK 1.8 in Jenkins

Step 6: Navigate down to Source Code Management Section.

Enter repository information in source code management

Copy your Git repository URL (it must be ending with .git extension) and paste it in Repository URL textbox. Select your Username and Password from the Credentials dropdown.

In the Branches to build section, specify the branch you have been working on.

Step 7: Navigate to Build section and type pom.xml in Root POM textbox. Then type the command you have been putting in cmd all this time to run your project on local sans the word “mvn”. Something like this:

command you put in your cmd

NOTE: If you are using multiple suite xmls in your project, you can make use of -D to specify the specific xml you wish to run.

If you have plenty of parameters with you, you can make use of -D and the variable name like this:

-Dvariable1="$variable1"

But remember this has to be defined in your code too or it will mean nothing to Jenkins.

Here’s an example of a parameterized variable that you will be putting in Goals and Options when dealing with user inputs:

how to create a new Maven job in Jenkins variables

Step 8: Click on Apply.

Click on Apply

It will show you the following screen:

save

Step 9: Click on Save. It will take you to your build.

save and apply

Step 10: Now click on Build Now to actually start your build.

how to create a new Maven job in Jenkins final

Enjoy amigos!

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

2 Responses

  1. March 6, 2019

    […] in the Goals and options textbox alongside mvn clean install command of maven. If you wish to know more about -D, check out our new maven job in jenkins article. […]

  2. May 10, 2019

    […] 1 […]

Leave a Reply