Deploying Applications with Jenkins Container

Falguni_Mirikar
4 min readJun 17, 2020

--

Whenever we want to launch the container to test our code, we have to do this process manually because our Jenkins program doesn’t know about the programming language in which the code is written so if our code is written in “php” then the container should have all the requirements installed to run a “php” code.

To overcome this drawback, we use Jenkins Job that detects the code (“html” or “php”) and launches the container accordingly for testing. If the website is not working properly then Jenkins sends the admin message container the log file of the failed job.

Task Description :

1. Create container image that has Jenkins installed using Dockerfile.

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

3. Create a job chain of Job 1, Job 2, Job 3 and Job 4 using build pipeline plugin in Jenkins.

4. Job1 : Pull the Github repository automatically when developers push the Code to Github.

5. Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code ( eg. If code is of PHP, then Jenkins 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 an extra Job (Job 5) for monitoring basis : If container where app is running fails due to any reason, then this job should automatically start the container again.

Creating the Dockerfile in RHEL_8

Create a directory in RHEL_8 VM :

mkdir ws
cd ws
vim Dockerfile

After creating the Dockerfile, type the following code :

Save the Dockerfile and start the build process :

Creating Multiple Jobs in Jenkins :

JOB-1

Pulling the code repository with Jenkins :

JOB-2 :

In this Job we will first have to check the type of programming language that the code is using and on the basis of the code we will create and run a container.

JOB-3 :

Creating a testing environment and checking if our code is working or not.

JOB-4 :

The main Job is to check if the code is working or not and if the code is not working, it will send an E-mail to Jenkins admin attaching the build log file if the Job fails in Jenkins.

JOB-5 :

This last Job monitors our containers, if due to any reason our container stops or terminates then this job will launch our container again after the failure.

At last after performing multiple jobs in Jenkins, we can visualize our jobs with the help of Jenkins build pipeline plugin.

After the Jobs are performed, the output of the working website and the pipeline plugin output looks like this :

Thus, the task of automating the code deployment is successfully done in Jenkins.

Checkout my GitHub repository for the code :

Thank you for reading!

--

--