AUTOMATED TESTING SYSTEM WITH JENKINS
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.
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.
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
JUST CLICK ON THE NEW REPOSITORY OPTION AS SHOWN IN ABOVE IMAGE. It will land you to the page as shown below.
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.
STEP - 4 Now you have also to initialize the files in the directory as shown below.
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.
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.
HERE AN AUTOMATIC SYSTEM IS CREATED THROUGH WHICH THE CODE WILL BE UPLOADED BY ITSELF AS SOON AS THE FILE IS COMMIT.
- GO TO THE PATH : .git/hooks
- CREATE A FILE WITH NAME post-commit with the help of the notepad and write the code as shown below.
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.
STEP - 8 Make an another branch in the same repository by using the command as shown below.
TO KNOW NUMBER OF BRANCHES IN YOUR REPOSITORY JUST TYPE THE COMMAND SHOWN BELOW.
TO SWITCH TO THE BRANCHES JUST WRITE THE COMMAND
=> git checkout <BRANCH NAME>
HERE IN THIS PICTURE THE SWITCH IS DONE TO DEV1 BRANCH.
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.
STEP - 10 You can push your code to your other branch (dev1) by using the command as shown below(for the first time)
PUSH (IF MADE)THE ANOTHER FILE TO THE BRANCH AS SHOWN.
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)
NOW IN THE DEV1 BRANCH (BUT CAN VIEW AFTER SWITCHING TO DEV1 BRANCH THROUGH GITBASH)
SAME FOR THE WEB.HTML FILE (AT MASTER BRANCH)
CODE OF WEB.HTML (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.
Now start the docker by using the command systemctl start docker as shown below.
BEFORE LAUNCHING JENKINS STOP THE FIREWALL OF THE OPERATING SYSTEM BY USIING THE COMMAND AS SHOWN BELOW.
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.
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.
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.
- GITHUB
- BUILD PIPELINE
- DELIVERY PIPELINE
NOW WE ARE READY TO CONFIGURE JOB1.
#JOB 1
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
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
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
AFTER CONFIGURING THE EACH JOB CLICK ON THE BUILD NOW (CLICK ON THE JOB NAME IN JENKINS DASHBOARD) AS SHOWN BELOW.
IF ANY ERROR OCCURS YOU CAN CHECK THE ERROR IN THE CONSOLE OUTPUT IN THE RESPECTIVE JOB.
YOU CAN CONFIGURE YOUR CODE FROM THE CONFIGURE OPTION AS SHOWN BELOW.
IF ALL THE JOBS ARE BUILD SUCCESSFULLY IT WILL LOOK AS SHOWN BELOW.
CLICK ON THE NEW VIEW AS SHOWN BELOW.
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.
NOW AFTER CREATING YOUR BUILD PIPELINE IS READY TO DEPLOY AND JUST CLICK BUILD NOW ON THE PAGE YOU ARE LANDED AS SHOWN BELOW.
SAME YOU CAN DO FOR THE .DELIVERY PIPELINE
- CLICK ON THE NEW VIEW. SELECT FOR THE DELIVERY PIPELINE.
- GO AT LAST OF THE PAGE AND CLICK ON COMPONENT AND THERE SELECT THE INITIAL JOB AND SAVE IT.
- DELIVERY PIPELINE IS READY TO DEPLOY.
IT WILL BE LOOKING AS SHOWN BELOW.
YOU CAN NOW ACCESS THE PAGE ON THE WEBSERVER BY THE IP OF RHEL8 WITH PORT NO. MENTON IN DOCKER AS SHOWN BELOW.
HURRAY!! YOUR AUTOMATED SYSTEM IS READY.