DevOps Assembly Lines Task 2
Share
Explore

icon picker
Devops Assembly line Task II

Automating testing and deployment operation using containerized jenkins

Project Brief Definition

In this project i am going to use git, github, docker, jenkins inside docker to automate testing and deployment of software or web application.
Let's see step by step process

1. Create Dockerfile for creating jenkins docker image


This is the Dockerfile code for creating jenkins docker image

1.png
Run the following command in the same directory to create jenkins docker image
docker build -t jenkins:latest .

2. Launch the jenkins container using the following command

docker container run -it --name jenkin -v jen:/root/ -p 8888:8080 jenkins:latest

Here jen is the volume, attached to the root folder of the jenkins container for keeping the data persistent. To create the volume for docker container use the following command
docker volume create volume_name (in my case volume_name is jen)
After this setup jenkins, install required plugins like Git, Email notification and Build pipeline.

3. Let's create the jobs in the jenkins for automation


Job 1: Pull the code from github repository as soon as developer commit

In Source Control Management section put the Github repository url and branch name

1.png


In Build trigger section select Poll SCM for checking the github repository every minute

3.jpg

In the Build section from Add build step select Execute shell and put the following code in the command box

4.jpg
Click on Apply and Save

Job 2: By looking at the file name launch the respective webserver container for testing


In Build trigger section select Build after other projects are built and put Job 1 in the Project to watch box and check Trigger only if build is stable

5.jpg


In the Build section from Add build step select Execute shell and put the following code in the command box

6.jpg

Click on Apply and Save

Job 3: Check whether the site is working or not

In Build trigger section select Build after other projects are built and put Job 2 in the Project to watch box and check Trigger only if build is stable

7.jpg

In the Build section from Add build step select Execute shell and put the following code in the command box


8.jpg

Click on Apply and Save

Job 4: If app is working fine merge the code from developer branch to master branch

In Source Control Management section put the Github repository url and branch name, from Additional Behaviour select Merge before build and put Name of repository as origin, Branch to merge to as master and leave the other boxes as it is

2.jpg

In Build trigger section select Build after other projects are built and put Job 3 in the Project to watch box and check Trigger only if build is stable

10.jpg

In the Post-build Actions section select Git publisher and check Push Only if Build Succeeds, Merge Results and click on Add Branch put master in Branch to push and origin in Target remote name

11.jpg

Click on Apply and Save

Job 5: After merging into master branch pull the code from github repository from master branch and deploy it in production environment

In Source Control Management section put the Github repository url and branch name

3.jpg

In Build trigger section select Build after other projects are built and put Job 4 in the Project to watch box and check Trigger only if build is stable

13.jpg


In the Build section from Add build step select Execute shell and put the following code in the command box

14.jpg

Click on Apply and Save

Job 6: Send email notification to developer if site will not work

In Build trigger section select Build after other projects are built and put Job 3 in the Project to watch box and check Trigger even if the build fails

15.jpg

In the Post-build Actions section select Editable Email notification and put the email address of developer, subject and message content (Note: We need to configure SMTP server for sending mail. For this go to Manage jenkins -> Configure -> Extended Email notification and put the details there)

4.jpg


Click on Apply and Save

Job 7: Monitoring the Production environment container if it fails it will launch another one

In Build trigger section select Build periodically for continuously monitoring the Production environment container


In the Build section from Add build step select Execute shell and put the following code in the command box

18.jpg


Click on Apply and Save

That's all our setup is ready.
Now as soon as the developer commit new code in the repository it will get automatically tested if it will work fine then it will get automatically deployed in the production environment and if it will not work then developer will get informed through an email notification.
Following is the Build pipeline view of the Jobs in Jenkins

Thank you very much to Mr. Sir
Check out for more product management-related templates.

👉 Get started with


Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.