Automation of Testing and Production via Jenkins

What is automation?

4 min readJun 27, 2020

--

It’s the process of repeating a set of tasks (or instructions )instead of manually doing those tasks every single time.

What is the need for automation?

This allows the devs to focus on other tasks while being productive, reduce errors (or modifying the instructions for easier implementation), and most importantly free up time that can be spent on other work.

Project Objectives:

Job1:

If Developer push to dev-branch then Jenkins will fetch from dev and deploy on dev-docker environment.

Job2:

If Developer push to master branch then Jenkins will fetch from master and deploy on master-docker environment.
both dev-docker and master-docker environment are on different docker containers.

Job3:

Manually the QA team will check (test) for the website running in dev-docker environment. If it is running fine then Jenkins will merge the dev branch to master branch and trigger Job2

Procedure as Follows:

We begin by creating a Repo in Github. Then we clone it into our system.

Now the Repo has been cloned

Create a HTML page :

<html>
<head>
<title>Webpage for the Task Demo</title>
</head>
<body bgcolor="orange">
<h1> this is in the production unit</h1>
</body>
</html>

Add a post-commit hook in the .git/hooks directory in .In order to commit automatically as the code has been pushed

Once the code has been pushed into the specified repo , First Job will be executed .

Job1:

Make sure you mention your repo properly

As we use Git as our SCM , we can directly enter the repo’s link and list what branch to monitor .

We Poll the SCM so that it triggers the build so that whenever it notices a change the Job is triggered. So, the 5 “ * ”imply that The Jenkins will monitor the specified repo each and every minute.

Here we are hosting the production server by moving the repo to “ /root/production” directory and then we mount it to “ /usr/local/apache2/htdocs” directory .

Now as you can see, its active.

Job2:

This Job triggers when any change has been done by the developer in the prog1 branch.

(prog1, as in programmer1/developer1)

So here we have to include the prog1 in our Branch Specifier.

As mentioned above 5 “ * ”s imply that it checks each and every minute.

Now we can host a test server which has the added content from the Developer:

Job3:

Now, The Q/A team will be testing the webpage which is running in a developer’s docker environment.So if it’s running perfect , then Jenkins will merger the prog1 branch into the master branch hence triggering the first Job

Once the Dev’s code has been tested , Jenkins will merge prog1 into master branch.

This is done so that the third Job will only run once second Job is stable.

This is the post-build action, it’ll trigger the first Job so that the changes done in the testing period are applied to the production server.

In the end, changes to the team’s production server has been made and that’s how easy it is to automate different actions via Jenkins.

Thank you for the time.

--

--