{"id":9715,"date":"2021-12-28T04:40:04","date_gmt":"2021-12-28T04:40:04","guid":{"rendered":"https:\/\/blog.cloudthat.com\/?p=9715"},"modified":"2024-06-25T11:05:50","modified_gmt":"2024-06-25T11:05:50","slug":"a-tutorial-on-building-a-deployment-pipeline-with-custom-jenkins-image","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/a-tutorial-on-building-a-deployment-pipeline-with-custom-jenkins-image","title":{"rendered":"A Tutorial on Building a Deployment Pipeline with Custom Jenkins Image"},"content":{"rendered":"<table border=\"3\">\n<tbody>\n<tr>\n<td><span style=\"color: #000080;\"><strong>TABLE OF CONTENT<\/strong><\/span><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#Problem Statement\">Problem Statement<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#Prerequisite\">Prerequisite<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#Important steps used\">Important steps used<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#Github clone\">Github clone<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#GitHub Configuration\">GitHub Configuration<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#Deployment configuration\">Deployment configuration<\/a><\/td>\n<\/tr>\n<tr>\n<td><a href=\"#Test Job Configuration\">Test Job Configuration<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1 id=\"Problem Statement\">Problem Statement<\/h1>\n<p>Creating a Dockerfile to create Jenkins container image and then automate provisioning the environment to deploy the webpages with the help of Jenkins.<\/p>\n<h1 id=\"Prerequisite\">Prerequisite<\/h1>\n<p>Docker must be installed and in running state, CENTOS system is employed in this tutorial. (If you are using other operating systems then use their respective package and service manager.)<\/p>\n<p>We have created a Dockerfile using a base image as centos 7 and then created a Jenkins container image.<\/p>\n<h1 id=\"Important steps used\">Important steps used<\/h1>\n<p>Jenkins requires java to be installed in the backend,<br \/>\n2. <strong><em>Wget<\/em><\/strong> is installed to download Jenkins official repository from the web,<br \/>\n3. Then the <strong><em>gpg-key<\/em> <\/strong>is added for the yum repo to get authorized,<br \/>\n4. We install Jenkins as the yum repo is configured with proper <strong><em>gpg-key<\/em><\/strong>,<br \/>\n5. To start Jenkins service we have to install <strong>service<\/strong> utility,<br \/>\n6. For the connection to Jenkins server, it must be exposed on 8080 port,<br \/>\n7. Finally, we have a script that starts Jenkins service (with the help of the service utility) and puts the container in sleep mode so that it will not get stopped.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture130.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9717\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture130-300x99.png\" alt=\"\" width=\"530\" height=\"175\" \/><\/a><\/p>\n<p><strong>Docker file to create Jenkins Image<\/strong><\/p>\n<h1 id=\"Github clone\">Github clone<\/h1>\n<p>We can create the docker file by using the following command:<br \/>\n<strong><em>docker build -t image_name: version workspace_name<br \/>\n<\/em><\/strong>where workspace_name = absolute path where the Dockerfile is present.<\/p>\n<p>We will now launch the Jenkins server by using the above image.<\/p>\n<p><em>Now using this image, we have launched the Jenkins container and created five jobs<\/em><\/p>\n<ol>\n<li><em>Github_clone <\/em><\/li>\n<li><em>Deploy <\/em><\/li>\n<li><em>Test <\/em><\/li>\n<li><em>Notify<\/em><\/li>\n<li><em>Monitor<\/em><\/li>\n<\/ol>\n<p>This job will clone from the GitHub repository on the Jenkins server and hence this code will be used for the deployment of the website.<\/p>\n<p><strong>Image-1:<\/strong> It depicts the <strong><em>repo URL<\/em><\/strong> from where the code will be fetched for the deployment.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture213.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9718\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture213-300x148.png\" alt=\"\" width=\"531\" height=\"262\" \/><\/a><\/p>\n<p><strong>Image-1<\/strong><\/p>\n<p><strong>Image-2:<\/strong>\u00a0 It depicts the<strong><em> &lt;username&gt;<\/em><\/strong> <strong><em>@&lt;ip&gt; <\/em><\/strong>(to ssh plugin) of the server on which the given commands are to be executed (ignore the warnings if any). The command is to copy the github_clone repo from the container to the document root of the web server (so that it will be hosted).<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture310.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9719\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture310-300x121.png\" alt=\"\" width=\"531\" height=\"214\" \/><\/a><\/p>\n<p>Image-2<\/p>\n<h1 id=\"GitHub Configuration\">GitHub Configuration<\/h1>\n<p><strong>Deploy<\/strong>:<\/p>\n<p>We run a container and mount the repo in the document root inside the container and then this job will deploy the code into the container by using docker in the Redhat system. <strong><em>ssh plugin<\/em><\/strong> is used to deploy it on a remote host because Jenkins is running on the container, therefore, we require to build this job on a remote host.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture48.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9720\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture48-300x136.png\" alt=\"\" width=\"529\" height=\"240\" \/><\/a><\/p>\n<p>Image-3<\/p>\n<h1 id=\"Deployment configuration\">Deployment configuration<\/h1>\n<p>If the code that is used is written in some other language then we can install its respective interpreter using the <em>yum install <strong>&lt;interpretor package name&gt;<\/strong> <\/em>(e.g if PHP is used then install <strong><em>PHP-CLI<\/em><\/strong>).<\/p>\n<p><strong>Test<\/strong>:<\/p>\n<p>This job will check the status code of the web pages given by the browser and if some bugs show up then a notification will be sent to the developer with the error message embedded in it.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture55.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9721\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture55-300x147.png\" alt=\"\" width=\"527\" height=\"258\" \/><\/a><\/p>\n<p>Image-4<\/p>\n<h1 id=\"Test Job Configuration\">Test Job Configuration<\/h1>\n<p>Using the email plugin the email notification is configured, which can be configured as shown:<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture68.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9722\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture68-300x88.png\" alt=\"\" width=\"528\" height=\"155\" \/><\/a><\/p>\n<p>Image-5<\/p>\n<p><strong>Monitor<\/strong>:<\/p>\n<p>This job is to monitor the deployment job, So, if the container crashes or fails it will automatically create a new container for the use.<\/p>\n<p><a href=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture76.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-9723\" src=\"https:\/\/content.cloudthat.com\/resources\/wp-content\/uploads\/2022\/11\/Picture76-300x185.png\" alt=\"\" width=\"530\" height=\"327\" \/><\/a><\/p>\n<p>Image-6<\/p>\n<h1><strong>About CloudThat:<\/strong><\/h1>\n<p>CloudThat provides end-to-end support with all the AWS services. As a pioneer in the Cloud Computing consulting realm, we are\u00a0 AWS (Amazon Web Services) Advanced Consulting Partner, and Training partner. We are on a mission to build\u00a0a robust\u00a0cloud computing ecosystem by disseminating\u00a0knowledge on technological intricacies within the cloud space. Read more about <a href=\"https:\/\/www.cloudthat.com\/expert-advisory\/\" target=\"_blank\" rel=\"noopener\"><strong>CloudThat\u2019s Consulting and Expert Advisory.<\/strong><\/a><\/p>\n","protected":false},"author":219,"featured_media":9725,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3606,3607],"user_email":"prarthitm@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/9715"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/219"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=9715"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/9715\/revisions"}],"predecessor-version":[{"id":43283,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/9715\/revisions\/43283"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=9715"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=9715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}