Task 2: Automated Environment Deployment using Jenkins

Task 2: Automated Environment Deployment using Jenkins

OBJECTIVE : The objective of this article is to give a basic idea on how to use DevOps tools like Jenkins, to automate procedure of deploying the code on the respective container. Moreover, this article gives a basic understanding of some of the feature of Jenkins such as Job Chaining, email notification, etc. which garnishes the delivery of application. We will create an environment which will achieve all this deployment .

1. To create container image that has Jenkins installed in it using Dockerfile.

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

3. Create a job chain of some jobs using build pipeline plugin in Jenkins.

4. job1 to pull the Github repo automatically when some developers push repo to Github and 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 should start the container that has PHP already installed ).

5. job2 to test the app if it working or not. If app is not working , then send email notification to developer with error messages.

6. job3 for monitoring : If container where app is running fails, due to any reason, then this job should automatically start the container again.

Pre-requisite :

  • OS: Base OS is Windows 10. Server OS is RedHat Enterprise Linux 8 (RHEL8) in Virtual Box.
  • In RHEL8 some of the softwares needed are Docker (also need the php image downloaded in it), Jenkins (also github, build pipeline and email extension plugin should be installed in it).
  • In Windows we need git bash software.
  • At the starting stop the firewalld in RHEL8 and start the docker and jenkins services.


1. Building Container Image for Jenkins

To create a container image containing Jenkins installed in it, create Dockerfile as follows:

No alt text provided for this image

To build an image using Dockerfile run command: docker build -t imagename .

This command searches for the dockerfile in the directory . In our case /ws

No alt text provided for this image

2. Launching Jenkins Container:

This step launches the container which has Jenkins services enabled: docker run -it --privileged -v /:/host --name myjenkins1 myjenkins:v1

To get the password for Jenkins

No alt text provided for this image

Download required plugins: 1. Build Plugin, 2. Git and Git Hub plugin, 3. Email Extension plugin

Job 1

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

Job 2

In this job we are deploying our code. Here we select one different trigger. Means as soon as job1 will complete job2 will start automatically. Also this job at first check if in our folder any php code exist or not. If yes then it will start the php container.

No alt text provided for this image

Job 3

No alt text provided for this image

JOB 4 This job will keep on checking each minutes if my docker container is running or not.These 5 start means each minute this job will automatically triggers itself.

No alt text provided for this image

Finally the build is deployed and if there is any failure an email will be sent

No alt text provided for this image


To view or add a comment, sign in

More articles by Samir Sanyal

  • AWS EKS TASK(Kubernates Cluster on AWS)

    OBJECTIVE : We will use AWS EKS service by which we will create and deploy a K8S cluster in AWS in which master node is…

  • Task 1 for Hybrid Multi-Cloud Training

    Terraform is an open source infrastructure as tool software tool created by HashiCorp . It enables users to define and…

  • DevOps Automation

    Now in today's world automation is one of the most efficient and sought after way of deployment . So as to learn this…

Insights from the community

Explore topics