What is Maven goal in Jenkins?

Earlier, we had learnt How To Install Maven in Eclipse and then we learnt How To Create Maven Project in Eclipse. Today in this post, we are going to see How To Execute Maven Project Using Jenkins. To do this, we need to have the following

i. Maven – Check this post on Installation of Maven.
ii. Maven Project – Check this post on Creating Maven Project.
ii. Jenkins – Check this post on Installation of Jenkins.

Firstly install Maven in Eclipse IDE and create a Maven Project. Next, open Jenkins and create a new Job to execute Maven Project using Jenkins.

Execute Maven Project Using Jenkins:

In this article, we see how to execute maven project using jenkins.

Click on New Item link to create a job on Jenkins

What is Maven goal in Jenkins?

Step 2:- Provide the job description

Step 3:- In Source Code Management, Jenkins supports CVS and Subversion out of the box, with built-in support for Git, and also integrates with many other version control systems via plugins. We will look into these details in next articles.

Now lets make it simple and select 'None' to execute from local machine.

Step 4:- Build Triggers, We have multiple options like 'Build periodically', 'Poll SCM', 'Build whenever a SNAPSHOT dependency is built, etc. Example, if you select 'Poll SCM' option, Jenkins will poll the repository for changes based on the cron expression specified. We will see more details in the coming tutorials.

Please select any of the option based on your needs.

Step 5:- In Build, We need to tell Jenkins where to find pom.xml file. Please specify the path of your pom.xml file in Build Root POM and Specify 'Goals and options', in this example 'clean test'.

What is Maven goal in Jenkins?

Below is the pom.xml file :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ma... http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.easy</groupId>
   <artifactId>mavenparameterize</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>My Maven Project</name>
   <description>This is a simple Maven Project</description>
   <properties>
      <jre.level>1.8</jre.level>
      <jdk.level>1.8</jdk.level>
   </properties>
   <build>
      <plugins>
         <!-- Compiler plug-in -->
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
               <source>${jdk.level}</source>
               <target>${jdk.level}</target>
            </configuration>
         </plugin>
         <!-- Added Surefire Plugin configuration to execute tests -->
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
               <suiteXmlFiles>
              <suiteXmlFile>patienttests.xml</suiteXmlFile>
               </suiteXmlFiles>
               <systemPropertyVariables>
                  <browserName>firefox</browserName>
               </systemPropertyVariables>
            </configuration>
         </plugin>
      </plugins>
   </build>
   <dependencies>
      <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.9.8</version>
         <scope>test</scope>
      </dependency>
   </dependencies>
</project>

[Optional]

Step 6:- In Build Settings, If you want to send an email notifications, you can check 'Email Notification' and add Recipients address.

Step 7:- In Post Build Actions, You can chose steps such as Archive Artifacts, Publish Results etc.

After executing the Build, you can view the result as below:

What is Maven goal in Jenkins?


  • ‹ Parametrize to Execute TestNG.xml using Maven
  • Jenkins configuration with Maven and GitHub ›

Jenkins Tutorials: 

Jenkins Continuous Integration Tutorial

  • Add new comment

Comments

Jenkins job for TestNG suites

Permalink Submitted by Vidhya on Tue, 06/12/2018 - 03:09

Hi I refer your link many a times. Thank you . I have a scenario where I have multiple testNG suites. I have Jenkins configured and I am able to run the suites though the POM .I am trying to check with you if there is a way we can trigger the Jenkin job seperately for each testNG suite. This is basically each suite takes about an hour so I want to schedule separate jobs so that we don't have to wait too long for all the suites to run completely.

  • reply

How to get each module pom.xml

Permalink Submitted by Ganesh on Fri, 01/11/2019 - 05:25

We work for different modules. My question from where will i get this ROOT POM : POM.XML do we have to configure it.

  • reply

Add new comment

Your name

Subject

Comment *

More information about text formats

CAPTCHA

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

What are the Maven goals?

A Maven plugin is a group of goals; however, these goals aren't necessarily all bound to the same phase. As we can see, the Failsafe plugin has two main goals configured here: integration-test: run integration tests. verify: verify all integration tests passed.

What is Maven used for in Jenkins?

Maven. Purpose. Jenkins is a CI/CD tool, which uses various other tools/plugins to automate the complete build cycle. Maven is a build lifecycle management tool that helps in dependency management and creating automated builds.

What are Maven goals in Devops?

Maven is a powerful build automation tool that is primarily used for java based projects maven address two critical aspects of building software first it describes how software is built and second it describes dependencies it uses conventions for build procedure and only exception need to be written down an XML file ...

How do I specify Maven goals in Jenkins?

Go to Jenkins Dashboard ->Manage Jenkins ->Manage plugins ->Available ->Maven Integration ->Install..
Go to Manage Jenkins->Global tool configuration->Maven -> Add Maven_home variable value (i.e. path of the maven file on your system)..