Skip to main content

Configure Maven Project in to Jenkins and Run

As we all know, maven is a build / project management tool, based on the concept of a project object model (POM) which contains every information about your project. Maven allows a project to build using its project object model to manage builds, dependencies, releases and documentation which are all managed from the pom.xml file.
Maven defines a standard way to build the projects, test, and deploy project artifacts. It provides a framework that enables easy reuse of common build logic for all projects following Maven's standards. We discussed maven in detail earlier here and hope you have configured maven.

First lets Create a simple maven project in Jenkins

Step 1:- Click New Items on the left menu
->Enter Project Name in “Item name” field
-> Select Maven Project
->Click OK

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'.





POM.xml format like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.Learn</groupId>
  <artifactId>POM</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>POM</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>3.11.0</version>
</dependency>

<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.14.2</version>
    <scope>test</scope>
</dependency>
   
<dependency>
    <groupId>com.relevantcodes</groupId>
    <artifactId>extentreports</artifactId>
    <version>2.40.2</version>
</dependency>
      
  </dependencies>
  
  <build>
<plugins>
<!-- Compiler plug-in -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.level}</source>
<target>${jdk.level}</target>
</configuration>
</plugin>
<!-- Below plug-in is used to execute tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<!-- TestNG suite XML files -->
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
  
</project>

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:


Comments

Popular posts from this blog

Eclipse New Maven Project: Could not resolve archetype

Close Eclipse Delete repository folder (you can find it in C:\Users{your user}.m2) Open Eclipse again. It will install maven repository automatically down v Open Window > Preferences Open Maven > Archetypes Click 'Add Remote Catalog' and add the following: Catalog File:  http://repo1.maven.org/maven2/archetype-catalog.xml Description: maven catalog

How to setup Appium for mobile automation

GitHub is a code hosting platform for version control and collaboration.  When a project is to be created, constant changes are made to the code. Version control systems keep these revisions straight, and store the modifications in a central repository.   A repository is a location where all the files for a particular project are stored. Each project will have its own repository, and can be accessed by a unique URL. Step 1: Install Appium-desktop-setup-1.2.6 (from the link Appium.io) Step 2: Install JDK Step 3: Install android studio-bundle (from developerandroid.com) Step 4: Go to AppData->Local->Android->Sdk Step 5: Copy the above path and set the path of a new environment variable “ANDROID_HOME” Step 6: Copy the above path, append \tools and add it in the path variable Steps 7: Copy the path from Step 5, append \platform-tools and add it in the path variable Step 8: Go to AppData->Local->Android->Sdk->tools->bin->uiautomatorview...

Setup Grid and run your test script on different Machine

1. selenium-server-standalone-3.11.0.jar should download on our local machine. we can download this from here  https://www.seleniumhq.org/download/ 2. After that open the command prompt and go in to the drive where we have downloaded "selenium-server-standalone-3.11.0.jar" file and run the command "java -jar selenium-server-standalone-3.11.0.jar -role hub " 3. Once this will execute successfully we can see on console "Selenium Grid hub is up and running" 4. Now we can see GRID console on browser by opening this url:  http://localhost:4444/grid/console 5. Now GRID is setup successfully 5. Now we have to register Node machine with GRID. For this we will open the node machine and download "selenium-server-standalone-3.11.0.jar", chrome driver, Firefox driver form here  https://www.seleniumhq.org/download/ 6. After that we have to register node machine with GRID by running this command using command prompt : For Chrome Browser run this command ...