Task 2: Automated Web Development and Testing using Jenkins

Peeyush Yadav
5 min readAug 25, 2021

Task Description:

  • Create a container image that had Jenkins installed using the docker file.
  • When we launch this image, it should automatically start the Jenkins service in the container.
  • Create a job chain of job1, job2, job3, and job4 using the build pipeline plugin in Jenkins
  • Job 1: Pull the GitHub repo automatically when some developers push the repo to GitHub
  • Job 2: By looking at the code or the program file, Jenkin should automatically start the respective language interpreter install image container to deploy code (eg. if the code is of PHP, then Jenkins should start the container that has PHP already installed)
  • Job 3: Test your app if it is working or not
  • Job 4: If the app is not working, then send an email to the developer with error messages.
  • Create one extra job 5 for monitor: In the container where the app is running, if the same fails due to any reason then this job should automatically start the container again.

Pre-requisites of tasks:

  • Linux (RHEL 8)
  • Git
  • Docker
  • Dockerfile

Step 1: Dockerfiel for creating an image that has Jenkins installed.

  • Create a new directory to use as a workspace for this task and process.
  • Using any editor (like vi, or vim) type in the following commands giving the instructions for the docker file to install and configure the required services and software upon its initiation.
  • Build the image using the following command:

docker build -t <image name> : <version tag> <Dockerfile path>

The process of downloading and installing the requirements should begin and conclude successfully.

After creating having created the images, now we have to run the docker container using the command:

docker run -it — privileged -p 8081:8080 -v /:/host — name my-jen_app1 jenkins-image:app1

You will now get a special initiation password for Jenkins. This is the password that would be used while login in for the first time to set up the account in Jenkins.

Open your browser and go to port 8081 which was given by you to Jenkins to work over.

Create and set up the account details such as the password and the username for future usage over the same province.

Jenkins is now ready

Job 1: Pull the Github repo automatically when some developers push the repo to GitHub

  • Give you the GitHub repo link in the Source Code Management Section. Following which set the branch to master
  • Now type in the following in the Build section, by selecting Execute Shell

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

  • The above code is used to change the root by the chroot command and also checks the extensions.
  • If the file is a webpage file, it would be launched from an httpd image.

Job 3: Test your app if it is working or not

Job 4: If the app/website is not working, this job will send an email to a developer with an error message.

Before going in to Configure job we will update some settings related to email which is important for our job

Go to manage Jenkins

  • Configure Systems
  • Under email notification apply the following settings altogether.

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

Type in the following code in the Execute Shell tab for the Build Section

Finally, Creating a Pipeline.

First: Install the Build Pipeline

  • Manage Jenkins
  • Manage Plugins (and find the same under Available Tab)

Now click the New View to add a pipeline. Now you can Enable the Build Pipeline view Option and set the initial job to Job 1.

Now you can test your workflow process throughout and pipelines would indicate if there are any errors regarding the job chains and specifies to which job the error resides.

That’s it! The task is now completed. You can always tweak your code in the GitHub repository and then see the changes in the Pipelines (how they react each time).

Hope you had a great read. Thanks.

I duly thank Mr. Vimal Daga and his team for their guidance and team throughout this process of learning.

Looking forward to learning even further and share opportunities for the same.

Adios.

#worldrecordholder #vimaldaga #devopsbylw #jenkinsbbylw #jenkins #jenkinsbyvd #rightmentor #linuxworld #makingindiafutureready #righeducation

--

--