Monitoring tasks using Jenkins + Git + Docker.

Monitoring tasks using Jenkins + Git + Docker.

In this article I will show you how to monitor a basic CI/CD pipeline with the help of very useful tools like Jenkins, Git and Docker.

Prerequisites for the task:

The task is discussed keeping in mind that Git, Jenkins and Docker have already been configured in your system. So if you haven't done this yet, I highly suggest that you complete the configuration before commencing the task.

Task Description:

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. Job 1 : Pull the Github repo automatically when some developers push repo to Github.

5. Job 2 : 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. Job 3 : Test your app if it is working or not. If app is not working , then send email to developer with error messages.

7. Job 4 : If container where app is running fails due to any reason then this job should automatically start the container again.

Solution Overview:

At first, we are to create a container image that has Jenkins installed in it. This can be done by creating a Dockerfile with the following details:

No alt text provided for this image

Once we launch the container, the Jenkins service starts automatically. At first, the initial administrator password is stored in the "/var/lib/jenkins/secrets/initialAdminPassword" directory.

No alt text provided for this image

Now that we have set up Jenkins, we can proceed with accomplishing the required job chain.

Job 1 : In this step, the developer makes the required changes to the files in the local repository and pushes contents into the dev branch of the VCS (here GitHub).

Once this happens, the Job1 of Jenkins is responsible to download the contents from GitHub onto the server system. The job configurations are as follows:

No alt text provided for this image
No alt text provided for this image

Job 2 : This job is responsible to start the required container that is compatible with the respective file type ( Eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).

No alt text provided for this image

Job 3 : This job is responsible for testing the web-application and returning a true of false value once test is complete.

No alt text provided for this image

This job is also responsible of alerting the developer in case of any error. Jenkins is configured in the following manner:

No alt text provided for this image

Note: Make sure you have configured your SMTP server in the Configure System tab to successfully trigger e-mails from Jenkins.

Job 4 :  This job monitors the process of model training and creates a new container in case the previous container fails to build. Here Job 2 is triggered to re-create the image. The Jenkins job set up is shown below.

No alt text provided for this image

Please feel free to share your views on this article in the comments section below.

Thanks for reading!


要查看或添加评论,请登录

Krish Sabnani的更多文章

社区洞察

其他会员也浏览了