AUTOMATED TESTING SYSTEM WITH JENKINS

Rishabh Jain
9 min readJun 17, 2020

--

Hey! Curators here comes a blog of an amazing automated system which has potential to eliminate the human intervention and make it negligible . Just write the code for once in Jenkins and set for some options in it and you will see an automated testing system which automatically recognizes if the code is changed by the developer it automatically download the code , test it and the client can view all at your website.

JENKINS INTEGRATED SYSTEM

It is an awesome testing system. Just follow the steps mentioned below and you will experience the power and beauty of this system.

So, let’s go for it!

YOU SHOULD HAVE GIT BASH IN YOUR LOCAL SYSTEM AND ALL THE CODE IN TOUR LOCAL SYSTEM IS WRITTEN IN THE GIT BASH.

STEP - 1 Create a directory in your local system and write some code in the files as shown below.

DIRECTORY
CODE IN THE FILE

The file should have the extension HTML as it has to be uploaded on the webserver.

I have made two files here i.e. rishu.html and web.html in this explanation.

STEP - 2 Login to your Github and make a repository in it as shown

NEW REPOSITORY

JUST CLICK ON THE NEW REPOSITORY OPTION AS SHOWN IN ABOVE IMAGE. It will land you to the page as shown below.

REPOSITORY CREATION

JUST GIVE THE NAME OF THE REPOSITORY AND DO NOT INITIALIZE THE REPOSITORY WITH A README FILE. IF DONE YOU WILL NOT BE ABLE TO UPLOAD THE CODE BY YOU LOCAL SYSTEM.

STEP - 3 In your local system just write the command git init to initialize your repository as git repository.

INITIALIZING LOCAL REPOSITORY

STEP - 4 Now you have also to initialize the files in the directory as shown below.

ADDING FILE IN GIT

STEP- 5 Remotely add the repository to the github by copying the link of the repository and give the name for the URL of the repository as shown below.

REPOSITORY LINK IN GITHUB
NAME FOR URL IN GITBASH

STEP - 6 Commit the file which has to be uploaded on the github by writing git commit -m ‘’ <your commit>’’ and push the code by the code shown below for the first time and after that you can use git push.

GIT PUSH COMMAND

HERE AN AUTOMATIC SYSTEM IS CREATED THROUGH WHICH THE CODE WILL BE UPLOADED BY ITSELF AS SOON AS THE FILE IS COMMIT.

  1. GO TO THE PATH : .git/hooks
  2. CREATE A FILE WITH NAME post-commit with the help of the notepad and write the code as shown below.
GOING AND CREATING THE POST-COMMIT FILE
CODE IN POST-COMMIT FILE

JUST SAVE IT AND YOUR AUTOMATIC CODE PUSHING PROGRAM IS READY IN YOUR SERVICE.

STEP - 7 Here web.html file is pushed in the github and as you can see as soon as the file is commit and you push enter the pushing of the file starts.

WEB.HTML FILE
AUTOMATIC PUSHING STARTS

STEP - 8 Make an another branch in the same repository by using the command as shown below.

CREATING THE BRANCH

TO KNOW NUMBER OF BRANCHES IN YOUR REPOSITORY JUST TYPE THE COMMAND SHOWN BELOW.

NUMBER OF BRANCHES IN REPOSITORY

TO SWITCH TO THE BRANCHES JUST WRITE THE COMMAND

=> git checkout <BRANCH NAME>

HERE IN THIS PICTURE THE SWITCH IS DONE TO DEV1 BRANCH.

SWITCHING OF BRANCHES

STEP - 9 Now make the changes in the same files you made and pushed on the github as shown and push it to the github and you will see that a branch will appear in your github repository as shown below.

BRANCHES IN GITHUB REPOSITORY
FILES IN THE GITHUB AT DIFFERENT BRANCHES

STEP - 10 You can push your code to your other branch (dev1) by using the command as shown below(for the first time)

PUSHING OF CODE IN GITHUB

PUSH (IF MADE)THE ANOTHER FILE TO THE BRANCH AS SHOWN.

WRITING CODE
PUSHING THE CODE

NOW BEFORE MOVING TO THE NEXT STEP WE SHALL SEE THE CHANGES DONE IN THE FILES IN THE BRANCHES OF THE CODE AND YOU CAN VIEW IT BY SWITCHING TO THE BRANCHES.

USE (git checkout <BRANCH NAME>)

YOU CAN CLEARLY UNDERSTAND BY SEEING THE PICTURES BELOW.BY THIS YOU CAN ALSO USE IT FOR THE SECURITY PURPOSE(SECRET CODE OR PASSWORD)

OPENING RISHU.HTML FILE AT MASTER BRANCH
CODE IN THE FILE

NOW IN THE DEV1 BRANCH (BUT CAN VIEW AFTER SWITCHING TO DEV1 BRANCH THROUGH GITBASH)

OPENING FILE IN DEV1 BRANCH
CODE AT DEV1 BRANCH

SAME FOR THE WEB.HTML FILE (AT MASTER BRANCH)

OPENING FILE AT MASTER BRANCH
CODE OF WEB.HTML AT MASTER BRANCH

CODE OF WEB.HTML (AT DEV1 BRANCH)

OPENING FILE AT DEV1 BRANCH
WEB.HTML FILE CODE AT DEV1 BRANCH

IF IT IS DONE AS THE STEPS EXPLAINED HERE IT IS DEFINITE THAT YOU WILL BE SUCCESSFUL IN UPLOADING YOUR CODE AT DIFFERENT BRANCHES OF THE REPOSITORY.

NOW LET US NOW MOVE TO JENKINS!!

Before moving to the Jenkins first of all we need to start the JENKINS.

So, go to the RHEL 8 => Go to the Terminal => type command =>

systemctl start jenkins and you can check the status by the command systemctl status jenkins as shown below.

STARTING JENKINS

Now start the docker by using the command systemctl start docker as shown below.

STARTING DOCKER

BEFORE LAUNCHING JENKINS STOP THE FIREWALL OF THE OPERATING SYSTEM BY USIING THE COMMAND AS SHOWN BELOW.

STOPPING FIREWALL

NOW GO TO THE GOOGLE CHROME IN WINDOWS AND JUST LAUNCH THE JENKINS BY WRITING THE IP ADDRESS OF RHEL8 WITH PORT NO. 8080 AS SHOWN BELOW.

FOR IP OF RHEL8 YOU CAN USE ifconfig command as shown below.

IP OF RHEL8
JENKINS ACCESS AND ITS DASHBOARD VIEW

Now once the jenkins is accessed successfully you can create the job by the step by step process as shown below.

For creating the job click on the New Item (appeared on the leftmost side of the Jenkins Dashboard).By clicking on it you will be landed to the window as shown below.

CREATING JOB IN JENKINS

Write the job name and just click OK . You will be landed to the next page as shown below.

BEFORE THIS YOU NEED TO DOWNLOAD THE REQUIRED PLUGINS.

  1. GITHUB
  2. BUILD PIPELINE
  3. DELIVERY PIPELINE

NOW WE ARE READY TO CONFIGURE JOB1.

#JOB 1

JENKINS JOB 1 CONFIGURATION (A)
JENKINS JOB 1 CONFIGURATION (B)
JENKINS JOB 1 CONFIGURATION (C)
JENKINS JOB 1 CONFIGURATION (D)

NOW JUST CLICK ON SAVE AND YOU WILL BE AGAIN LANDED TO THE JENKINS DASHBOARD.MAKE AN ANOTHER JOB NAME IT AND CONFIGURE IT AS SHOWN BELOW.

#JOB 2

JENKINS JOB 2 CONFIGURATION (A)
JENKINS JOB 2 CONFIGURATION (B)
JENKINS JOB 2 CONFIGURATION (C)

NOW JUST CLICK ON SAVE AND YOU WILL BE AGAIN LANDED TO THE JENKINS DASHBOARD.MAKE AN ANOTHER JOB NAME IT AND CONFIGURE IT AS SHOWN BELOW.

#JOB 3

JENKINS JOB 3 CONFIGURATION (A)
JENKINS JOB 3 CONFIGURATION (B)

NOW JUST CLICK ON SAVE AND YOU WILL BE AGAIN LANDED TO THE JENKINS DASHBOARD.MAKE AN ANOTHER JOB NAME IT AND CONFIGURE IT AS SHOWN BELOW.

#JOB 4

JENKINS JOB 4 CONFIGURATION (A)
JENKINS JOB 4 CONFIGURATION (B)

AFTER CONFIGURING THE EACH JOB CLICK ON THE BUILD NOW (CLICK ON THE JOB NAME IN JENKINS DASHBOARD) AS SHOWN BELOW.

BUILD THE JOBS

IF ANY ERROR OCCURS YOU CAN CHECK THE ERROR IN THE CONSOLE OUTPUT IN THE RESPECTIVE JOB.

CONSOLE OUTPUT

YOU CAN CONFIGURE YOUR CODE FROM THE CONFIGURE OPTION AS SHOWN BELOW.

CONFIGURE

IF ALL THE JOBS ARE BUILD SUCCESSFULLY IT WILL LOOK AS SHOWN BELOW.

SUCCESSFULLY BUILDED JOBS

CLICK ON THE NEW VIEW AS SHOWN BELOW.

NEW VIEW IN JENKINS

YOU WILL BE LANDED TO THE PAGE. JUST GIVE THE NAME OF YOUR LIST SELECT THE BUILD PIPELINE AND SELECT THE JOBS TO ADD IN THE LIST.

BUILD PIPELINE

NOW AFTER CREATING YOUR BUILD PIPELINE IS READY TO DEPLOY AND JUST CLICK BUILD NOW ON THE PAGE YOU ARE LANDED AS SHOWN BELOW.

BUILD PIPELINE

SAME YOU CAN DO FOR THE .DELIVERY PIPELINE

  1. CLICK ON THE NEW VIEW. SELECT FOR THE DELIVERY PIPELINE.
  2. GO AT LAST OF THE PAGE AND CLICK ON COMPONENT AND THERE SELECT THE INITIAL JOB AND SAVE IT.
  3. DELIVERY PIPELINE IS READY TO DEPLOY.
DELIVERY PIPELINE
SELECTING THE JOB FOR DELIVERY PIPELINE

IT WILL BE LOOKING AS SHOWN BELOW.

DELIVERY PIPELINE

YOU CAN NOW ACCESS THE PAGE ON THE WEBSERVER BY THE IP OF RHEL8 WITH PORT NO. MENTON IN DOCKER AS SHOWN BELOW.

MASTER BRANCH DATA
DEV 1 BRANCH DATA

HURRAY!! YOUR AUTOMATED SYSTEM IS READY.

--

--

Rishabh Jain
Rishabh Jain

Written by Rishabh Jain

I am a tech enthusiast, researcher and an integration seeker. I love to explore and learn about the right technology and right concepts from its foundation.

No responses yet