Setting up an automation project in Jenkins for Continuous Integration

In my last blog post I stressed myself on making my viewers understand the importance and benefits of using continuous integration, where at the end of the blog I mentioned that there are several tools which can be used to achieve continuous integration. The most popular tool in this genre would be “Jenkins“. It is an open source continuous integration tool that is very popular now a days for continuous deployment.

Well I would be explaining my viewers today how can you use Jenkins to run your tests automatically.

Instllation


I am using an Ubuntu 16.04 machine. So I would be explaining the installation as per Debian standard.

  1. To install Jenkins in Ubuntu please follow the following set of instructions
    wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
    sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    sudo apt-get update
    sudo apt-get install jenkins
  2. After installation if you want to upgrade your Jenkins to the latest version you can follow the following set of instruction.
    sudo apt-get update
    sudo apt-get install jenkins

Pre-Requsites


  1. Java should be installed within the system with its class path set.
  2. Maven should be installed within the system with its class path set. For those who have no idea about maven let me just brief you about maven. It is a build tool that helps running your automation tests independent of any platform.
  3. Jenkins should be installed within the system. If Jenkins is locally installed then it will be running on port 8080.
  4. Eclipse should be up and running.
  5. Github should be installed within your system.

Creating a maven project using eclipse


To create a maven project using eclipse follow the required steps

Step-1: After opening eclipse goto File > Project > Maven Project. Follow the screenshot

eclipse2

Step-2: Set artifact id for archetype to ‘quickstart‘. Follow the screenshot

eclipse3

Step-3: Add a group id name and a artifact id name. These would basically be your packages under which you will be writing your tests. After this click on finish. Follow the screenshot.

eclipse4

Once your maven project is configured the directory structure would look something like this.

eclipse5

Now once your code is up and running push it to git hub and then we can configure Jenkins to run your automation code from git hub itself.

Setting up Jenkins


To set up Jenkins please follow the steps.

Step-1: Create a new project by clicking ‘New Item

jenkins1

Step-2: Select the option ‘Maven project‘. Give the name of the project and click on ok.

jenkins2

Step-3: Provide a description of the project if you want to. Next select Git as the option for Source Code Management.

jenkins3

Also enter the ‘repository url‘ and the ‘branch‘ on which the updated code is present

jenkins4

Step-4: Give the path of your root POM within the project and set the goal to clean install. This would basically make a clean build each time the script is executed. For first time you can set ‘clean install‘ for ‘Goals and Options‘. The next time you run the script you can change it to ‘clean test‘.

jenkins5

Step-5: Next if you click on the option ‘Build Now‘ on your extreme left the build would start and it would look something like this.

jenkin6

Now to remove complete dependency for triggering the Jenkins build you can set up a scheduler for Jenkins that would schedule the job to be build at a continuous period of time. Follow the screenshot to understand.

scheduler

You can also trigger the Jenkins build when a code is pushed onto git hub by checking the option “Build when a changed is pushed to GitHub“. Follow the screenshot to understand

scheduler2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s