Category Archives: Jenkins

What is Jenkins?

Jenkins is an open source automation tool written in Java with plugins built for Continuous Integration purpose. Jenkins triggers a build for every change made in the source code repository, for example, Git repository.

Once the code is built it deploys it on the test server for testing. Concerned teams are constantly notified about build and test results. Finally, Jenkins deploys the build application on the production server.

Jenkins achieves Continuous Integration with the help of plugins. If you want to integrate a particular tool, you need to install the plugins for that tool. For example it, Maven 2 project, Amazon EC2, HTML publisher etc.

Advantages of Jenkins include:
  • It is an open source tool with great community support.
  • It is easy to install.
  • It has 1000+ plugins to ease your work. If a plugin does not exist, you can code it and share with the community.
  • It is free of cost.
  • It is built with Java and hence, it is portable to all the major platforms.
Now here we look into How to setup Jenkins for a Maven project. :
Step 1 – Starting Jenkins: which can be started via command line or web application server.
1.Download Jenkins Zip file and extract it(i have downloaded for windows as I am setting it up on windows7).
2.In cmd go to the path you have extracted Jenkins (eg.C:\Program Files (x86)\Jenkins)
3.To start the Jenkins, run the command jenkins.exe start
-To restart the Jenkins: Jenkins.exe  restart
-To stop the Jenkins: Jenkins.exe  stop
4.By default, it will open up on 8080 port as  localhost:8080 (make sure nothing else is running on port 8080)
Step 2 – Creating and configuring user on Jenkins
1.To create a user go to Manage Jenkins->Manage Users->Create User->Provide the required information
2.Go to Manage Jenkins->Configure Global Security
-Check Enable security
-In Security Realm, select Jenkins own user database and check Allow users to sign up
-In authorization, there are multiple options select as per requirement
-Save once done
Step 3 – Configuring System

1.Go to Manage Jenkins->Configure System
2.Configure JDK
-Give the JDK name
-JAVA_HOME : C:\Program Files\Java\jdk1.7.0_45
3.Maven configuration
-Give a maven name
-MAVEN_HOME : C:\apache-maven-3.2.5\apache-maven-3.2.5-bin\apache-maven-3.2.5
4.Global Maven_OPTS
–Xmx512m
–XX:MaxPermSize=128m
5.Save once done
Step 4 – Adding Plugins
1.Go to Manage Jenkins->Add Plugins
2.Install the plugins which are required, Eg. GIT client plugin: which Shared library plugin for
other Git related Jenkins plugins,  GIT plugin: This plugin integrates GIT with Jenkins etc.
Step 5 – Creating jobs
1.Go to New Items->Give a project name in “Item name” field->select Maven project->click OK
2.Now configure the job
-Provide the description
-In Source Code Management, there are options for CVS project, Git etc,  select the one which is required
-In Build Triggers, there are multiple options like “Build when a change is pushed to GitHub”,
“Poll SCM”, “Build whenever a SNAPSHOT dependency is built” etc, select the required one
-Give the path of your pom.xml file in Build Root POM
– Give “Goals and options“  take a use case where the requirement is to install the code then give ”clean install”
3.configure the job as in the screenshot and don’t forget to save
Step 6 – Run the build(job) from home page and output should be.
Thanks for reading this article!

We have a automation Project ready which includes Maven, TestNG and Selenium WebDriver..
if not? then start creating a Automation project from following my previous blogs..

Creating a Maven Project :
http://blog.nbostech.com/2016/08/about-maven-its-usage-and-setup-in-automation/

Adding TestNG and a Sample Selenium WebDriver test :
http://blog.nbostech.com/2016/09/about-testng-its-usage-with-selenium-webdriver-sample-test/

We want our project to be Continuously integrated and continuously delivered..
For continuous integration, we should  place our project on the remote.. and for that we are using GitHub
For Continuous delivery, we should have a dashboard where we can Run our Project and View the Results.. and for that we are using Jenkins

To add the Project in GitHub and Run through Jenkins, These are the steps to be followed..
1. Download jenkins from the LST Release
Url : https://jenkins.io

2. Extract the Jar File..
Install Jenkins

After Successful installation

3. Go to the browser and hit
http://localhost:8080/
it asks you to unlock jenkins..

4. Unlock jenkins by giving the password from the mentioned path
i.e C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword
and click continue

Customize jenkins gets displayed

image1
5. Now select install suggested plugins
it takes few mins to install the plugins

6. Create First Admin User
Fill in the details
All Set.. you are ready to start using jenkins

Before Creating a job in Jenkins
Lets add our project in github

Steps to be followed to add your automation project in GitHub

1. Get signed up in Github.com

2. Create a new repository on GitHub.
Copy the repository url and save it somewhere..

image2

3. From the Git bash , go to your local project.
//Initialize the local directory as a Git repository.
4. Command : git init

image3

//Add all the files in your new local repository. This stages them for the first commit.
5. Command : git add .
// Commit the files that you’ve staged in your local repository.
6. Command : git commit -m “First commit”
// git remote add origin remote repository URL
7. Command : git remote add origin https://github.com/kathar1223/SeleniumTest.git
// push  your entire project into gitHub Repo
8. Command : git push -u origin master

image4

So you completed pushing your project into Github..
now lets run your project from jenkins..

Steps to be followed to Create a Jenkins Project.
1. Now open your jenkins.. http://localhost:3000
2. click newitem
3. select FreeStyle Project
give a name “SeleniumTest” and click OK
You see a new Project got created..

4. Install TestNG Results plugin in the Jenkins
To install Navigate to the below path
http://localhost:8080/pluginManager/available
Search for the TestNG Results plugin
Select and install it..

image9

5. We have to Configure our project..
Navigate to this link
http://localhost:8080/job/SeleniumTest/configure   and configure your project with the details

The below are the tabs we see on the page
1 . general tab
give some description about your project.

image5

2.Source Code Management
Select git option
We see Repositories field.. Give the url of your github project and leave other fields as it is

image6

3. Build Triggers
No change in it.

4. Build Environment
No Change in it.

5. Under Build
select invoke top-level Maven targets

image7

Add ‘test’ in the Goals Field

image8

6. Post-build Actions
select Publish TestNG Results

image10

 

we see TestNG Xml Report pattern as

image11

and Click Apply then Save..
Your Jenkins project is configured with your automation project

Steps to be followed to Run the Jenkins Project..

1.  Navigate to this path
http://localhost:8080/job/SeleniumTest/

2. On the left side.. we see a list of links displayed..

image12

3. Click on “Build Now” link..
this starts running of your project..
we can see build #1 running..

4.  Click on the build #1..
or Navigate to this path  http://localhost:8080/job/SeleniumTest/1/

5. On the left side we see a list of links displayed related to build #1
among these links two are useful for us..

  • Console Output : It’s shows us the log of our automation project.
  • TestNG Results : It shows us the output of the Project we ran..image14we can see the exact reason for failing of test

we can configure many things in Jenkins..  Will be posted in coming Blogs.