My First Step Towards Complete Automation!

Ankit Yadav
2 min readMay 6, 2020

Let’s directly jump into the DevOps world!

Pre-Requisite:

  1. Jenkins
  2. Docker
  3. Git/GitHub

Problem Statement —

We have two environments, production environment and development environment. We want to achieve automation wherein the development team pushes their code to GitHub. The testing team takes the latest code and performs testing and gives there approval to merge the code, so that it can be pushed to the production environment.

So how are we going to handle this?

We would be needing 3 Jenkin’s jobs:

Jenkins Jobs
  1. Job1 — will keep polling the Development branch:
This Job will point to development branch

It will keep polling the SCM and deploy the code on the testing environment.

sudo cp -v -r -f * /home/ay/Documents/Jenkins/DevOpsAssignment1/test_envif sudo docker ps | grep jenkins_wbs_1
then
echo “Already Running!”
else
sudo docker run -dit -p 8081:80 -v /home/ay/Documents/Jenkins/DevOpsAssignment1/test_env:/usr/local/apache2/htdocs/ — name jenkins_wbs_1 httpd
fi
Build section of Job1

2. Job 2— will keep polling the Master branch (Production branch) and deploy the code to the production environment:

sudo cp -v -r -f * /home/ay/Documents/Jenkins/DevOpsAssignment1/prodif sudo docker ps | grep jenkins_wbs_2
then
echo “Already Running!”
else
sudo docker run -dit -p 8081:80 -v /home/ay/Documents/Jenkins/DevOpsAssignment1/prod:/usr/local/apache2/htdocs/ — name jenkins_wbs_2 httpd
fi
cd /home/ay/applications/ngrok-stable-linux-amd64/
sudo ./ngrok http 80

We are also enabling tunneling here so that the web server is available to the outside world.

3. Job3 — Will be triggered by the testing team once they have completed their testing and give a green signal to merge the latest code with master branch.

This job will automatically merge the code from development branch to master branch.

We need to specify from which branch we need to merge.
The build trigger option enabled for the testing team.

Interestingly, once testing team triggers the 3rd Job, it will do the merging and eventually the 2nd Job would be invoked as it will find a change in the SCM and deploy the latest code to the production environment!

Hurray! That’s how easy it is :)

--

--