INTEGRATION of JENKINS , GIT AND DOCKER

Hirendra kumar
4 min readMay 17, 2020

I completed a project in DevOps training given by VIMAL DAGA sir , the project was -

About project :-

1. Create container image that’s has Jenkins installed using dockerfile

2. When we launch this image, it should automatically starts Jenkins service in the container.

3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins

4. Job1 : Pull the Github repo automatically when some developers push repo to Github.

5. Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).

6. Job3 : Test your app if it is working or not.

7. Job4 : if app is not working , then send email to developer with error messages.

8. Create One extra job job5 for monitor : If container where app is running. fails due to any reson then this job should automatically start the container again.

creating Dockerfile to make an image that has jenkins installed itself

I created a Dockerfile in which we have to create image that have preinstalled configure jenkins .

Docekerfile (preinstalled jenkins)

in Dockerfile we have some predefined keyword through which it works

FROM is used to pull the image from docker hub . In my case i pulled centos image.

The USER instruction sets the user name to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.

RUN executes commands in a new layer and creates a new image. E.g., it is often used for installing software packages.

CMD is used for to start jenkins serivce at the time of launching of the container.

To make a image we have to build Dockerfile using:

docker build -t image_name foldername(workspace)

image created myimage:v1

Now we have to launch a container with our customize image myimage:v1 using :

docker run -it - -priveleged - -user root -p 1212:8080 -v /var/run/docker.sock:/var/run/docker.sock -v/githubcode:/githubcode/- -name dev myimage:v1

JENKINS launched
JENKINS started

DESCRIPTION OF JOBS:-

job1 :

we have to create a job something like that whenever deveoper push the changing code to github then jenkins should automatically start pulling the data from github . For this in this job we provide github url to jenkins through which jenkins can contact to github and for pulling we create a remotely build triggered through which all content will come into centos folder as githubcode in my case.

for copying data:

cp -rvf * /githubcode/

copy data to centos folder

job2 :

job2 will be trigerred only when the job1 will be successfully done. Now in job2 the operation guys have to check the code given by developer and they should start the respetive interpreter . For this they have to grep the code as i did and according to the code launch the respective interpreter and deploy it into a container .

job3 :

in job3 we have to test the site , is it working fine or not . For this we have to obtain the status code for webserver . so as we know the status code for webserver is 200 . now if site is working fine the it should through message of success code 200 with exit 0, means succesfull. and the site will be tested in this way.

testing of site

job4 :

in job4 we have to send a message with a error to developer if site is not working fine. for this in jenkins we have to give email in SMTP and give the port of mail . now it will send message on failing of site to developer.

sending error message to developer

job5 :

in job5 we have to moniter all the previous because if any condition website fails then it should automatically start the container. For this we have to retrieve that container using grep . if it is working so it is success . and if it is not success then it will be failure and start container again .

all the five jobs are connected to each other somehow if any of goes down , it will be fail so job5 is very critical .

so the complete task is good example for continous integration with jenkins , docker and git.

THANK YOU!!!

--

--