Jenkins is a famous continuous integration tool which is
used in the industry.
Step 1: Lets create a
simple maven project.
a.
Set maven and java paths in environment
variables
JAVA_HOME=C:\Program
Files\Java\jdk1.8.0_111
M2_HOME=D:\Personnel\Softwares\apache-maven-3.3.9
path=%M2_HOME%\bin;%JAVA_HOME%\bin;
Step 2: Create a maven project.
Install
eclipse and create a maven project
Pom.xml
<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.google.com</groupId>
<artifactId>google-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>google-test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jre.level>1.8</jre.level>
<jdk.level>1.8</jdk.level>
<jre.level>1.8</jre.level>
<jdk.level>1.8</jdk.level>
</properties>
<dependencies>
<!--
https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.13.6</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>
<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>
TestNg.xml
<suite name="Test">
<test name="Test">
<classes>
<class name="com.google.com.google_test.NewTest"></class>
</classes>
</test>
</suite>
Setup Jenkins:
1.
Download Jenkins war file from https://jenkins.io/
2.
Strat Jenkins server; cmd>java –jar Jenkins.war
a.
Takes some time to deploy Jenkins in the local
system
3.
Browse: localhost:8080
a.
Asks for admin password
b.
You can get it at
c:\users\accoutnname\.jenkins\secrets\invalidAdminPassword
4.
Customize Jenkins
a.
Install Suggested plugins
5.
Now create Admin user
a.
Uname
b.
Password
c.
Confirm password
d.
Name
e.
Email
Create a new job in Jenkins:
Job name: First Job
Choose Freestyle project and say ok
Tab: General
Click on advanced, click on ‘use custom workspace’ and enter project directory
Tab: Build
Choose ‘execute windows batch command’
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_111
set M2_HOME=D:\Personnel\Softwares\apache-maven-3.3.9
set path=%M2_HOME%\bin;%JAVA_HOME%\bin;%path%
mvn clean test
save it.
This is how it looks like.
Just run it. ( click on build now)