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.
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.
Step 2: Click on New Item. It will navigate you to the following screen:
Step 3: Click on Maven Project and provide a name for your project.
Step 4: Once done, click on Ok button.
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.
Step 6: Navigate down to Source Code Management Section.
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:
NOTE: If you are using multiple suite
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:
Step 8: Click on Apply.
It will show you the following screen:
Step 9: Click on Save. It will take you to your build.
Step 10: Now click on Build Now to actually start your build.
Enjoy amigos!
2 Responses
[…] 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. […]
[…] 1 […]