{"id":4324,"date":"2019-10-10T07:28:59","date_gmt":"2019-10-10T07:28:59","guid":{"rendered":"https:\/\/cloudkul.com\/blog\/?p=4324"},"modified":"2019-10-24T10:38:52","modified_gmt":"2019-10-24T10:38:52","slug":"ci-cd-using-jenkins-and-bitbucket","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/","title":{"rendered":"CI\/CD using Jenkins and BitBucket"},"content":{"rendered":"<p>In this blog, we will learn how to Integrate Jenkins with bitbucket to automate the process of CI\/CD.<\/p>\n<p>Before we begin, let&#8217;s talk about what is Jenkins and what role it plays in the process of CI\/CD.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>WHAT IS JENKINS?<\/strong><\/p>\n<p><em>&#8220;Jenkins is a continuous integration tool that enables developers around the world to reliably build, test, and deploy their software.&#8221;<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>CI\/CD is the backbone of the modern DevOps environment. It bridges the gap between development and operations teams by automating the building, testing, and deployment of applications.<\/p>\n<p>&nbsp;<\/p>\n<p>For more information regarding Jenkins Installation and CI\/CD, you can refer the <a href=\"https:\/\/jenkins.io\/doc\/book\/installing\/\">link.<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>For this demo we will use the following:-<\/p>\n<ol>\n<li><em>Jenkins Server <\/em><span style=\"color: #3366ff\">v2.176.3<\/span><\/li>\n<li><em>Ubuntu Server <\/em><span style=\"color: #3366ff\">18.04 LTS<\/span><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>For this implementation you will need to download the following Jenkins plugins on a working Jenkins Setup:-<\/p>\n<ol>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/Bitbucket+Push+And+Pull+Request+Plugin\">Bitbucket Push and Pull request plugin<\/a>.<\/li>\n<li><a href=\"https:\/\/wiki.jenkins.io\/display\/JENKINS\/SSH+plugin\">Execute shell script over remote host using ssh<\/a>.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>Now lets come to the implementation part.<\/p>\n<p>For this implementation, we will launch an EC2 Instance (Ubuntu 18.04LTS) from our AWS console and install apache2 on it by executing the following commands:-<\/p>\n<pre class=\"lang:default decode:true\">sudo apt update\r\nsudo apt install apache2<\/pre>\n<p>&nbsp;<\/p>\n<p>Before beginning the Jenkins implementation, configure the following:-<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1. Add Bitbucket Credentials:-<\/strong><\/p>\n<p>If you have private repo you need to add the Bitbucket credentials into your Jenkins server.<\/p>\n<p>Log in into your Jenkins server and go to<em> Manage Jenkins-&gt; Configure Credentials-&gt; Credentials-&gt; System -&gt; Global Credentials(unrestricted)-&gt; Add Credentials -&gt; and select Username with password.<\/em><\/p>\n<p>(<em>Note:- No need to perform this step if you have a public repository.)<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/bitadffwefwf.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-4387 aligncenter\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/bitadffwefwf-300x92.png\" alt=\"\" width=\"755\" height=\"232\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2. Remote SSH Server Configuration:-<\/strong><\/p>\n<p>You need to add your AWS EC2 server under Jenkins.<\/p>\n<p>Log in into your Jenkins server and go to<em> Manage Jenkins-&gt; Configure Credentials-&gt; Credentials-&gt; System -&gt; Global Credentials(unrestricted)-&gt; Add Credentials -&gt; and select SSH Username with private key.<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/SSSSSHHHHHH.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-4390 aligncenter\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/SSSSSHHHHHH-300x115.png\" alt=\"\" width=\"777\" height=\"298\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>After this go to <em>Manage Jenkins -&gt; Configure System -&gt; <\/em>and under<em> SSH remote hosts check your SSH server connection.<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/Screenshot-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-4442 aligncenter\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/Screenshot-2-300x153.png\" alt=\"\" width=\"743\" height=\"379\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Bitbucket Implementation Part:-\u00a0<\/strong><\/p>\n<p>Log in to your Bitbucket account and go to your main repository.<\/p>\n<p>Under settings select <em>Webhooks and configure it as shown:-<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/webhooks-latest.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-4468 aligncenter\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/webhooks-latest-300x235.png\" alt=\"\" width=\"744\" height=\"583\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Webhooks\u00a0<\/strong>are just &#8220;user-defined HTTP callbacks&#8221;\u00a0 which are triggered by some events in the repo such as push, merge, etc. In our case, webhooks will trigger our Jenkins job in case of any push and merge in our repo.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Jenkins Implementation Part:-<\/strong><\/p>\n<p><span style=\"color: #333333\"><strong><em>Step1:-<\/em><\/strong><\/span><\/p>\n<p>Log in to your Jenkins server and go to -&gt; <strong>New Item -&gt; Freestyle Project -&gt;<\/strong> and create a new project with any name let&#8217;s say TEST-PROJECT.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/Screenshot-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-4386 aligncenter\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/Screenshot-3-300x80.png\" alt=\"\" width=\"694\" height=\"185\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong><em>Step2:-<\/em><\/strong><\/p>\n<p>Now go to your project and Under <strong>Source Code Management<\/strong> choose Git and give the link of your Bitbucket repo and under <strong>Branches to build <\/strong>select your main development branch.<\/p>\n<p>&nbsp;<\/p>\n<p><strong><em>Step3:-<\/em><\/strong><\/p>\n<p>Under <strong>Build Triggers\u00a0<\/strong>select <em>Bitbucket Push and Pull Request Plugin, <\/em>add Push event. Choose the Bitbucket Cloud Push event and mention the branch you want to monitor for any push\/merge event by the developers.s<\/p>\n<p>&nbsp;<\/p>\n<p><strong><em>Step4:-<\/em><\/strong><\/p>\n<p>Under <strong>Build <\/strong>select <em>execute shell script on remote host using ssh\u00a0<\/em>and select your ssh server credentials and under Command write the following:-<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">cd \/var\/www\/html\r\nsudo chmod 777 -R \/var\/www\/html\r\nsudo rm -rf index.html\r\nsudo echo \"CI\/CD Integration is successfull\" &gt; index.html<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/Screenshot-3-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-4449 aligncenter\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/Screenshot-3-1-300x124.png\" alt=\"\" width=\"802\" height=\"332\" \/><\/a><em>(Note:- It is not recommended to give 777 permission on \/var\/www\/html we are just giving 777 for demo purpose only)<\/em><\/p>\n<p>&nbsp;<\/p>\n<p>Save the job.<\/p>\n<p>Now go to your main repository in bitbucket, and perform any push\/merge operation on it which will result in the following;-<\/p>\n<ul>\n<li>The push\/merge event will activate our webhooks which will trigger our Jenkins job.<\/li>\n<li>\u00a0Our Jenkins job will ssh into our EC2 server and perform the commands specified under the step.<\/li>\n<li>Finally, we can check whether our job is working correctly by going to our server IP address:-<\/li>\n<\/ul>\n<p>Off<br \/>\n\ufffc<\/p>\n<p>On browsing your Apache2 server it should display the following result &#8211;<\/p>\n<p><a href=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/oie_kaH68IsTJqI8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4454 aligncenter\" src=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/oie_kaH68IsTJqI8-300x25.png\" alt=\"\" width=\"708\" height=\"59\" \/><\/a><\/p>\n<p>Now you have successfully Implemented CI\/CD using Bitbucket and Jenkins.<\/p>\n<p>&nbsp;<\/p>\n<p><strong><em>In case of any help or query, please\u00a0<a href=\"https:\/\/cloudkul.com\/contact\/\" target=\"_blank\" rel=\"noopener noreferrer\">contact us<\/a><\/em><em>\u00a0or raise a ticket at<\/em><\/strong><\/p>\n<p><strong><em>\u00a0<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\">support@webkul.com<\/a>.<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we will learn how to Integrate Jenkins with bitbucket to automate the <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"gallery","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[32,2,86,36],"tags":[65,16,228,206,3,94,43],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CI\/CD using Jenkins and BitBucket - Cloudkul<\/title>\n<meta name=\"description\" content=\"Integrate your Jenkins Server with Bitbucket to automate the process of CI\/CD and simplify the entire workflow. Trigger Jenkins Job via Bitbucket webhook.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CI\/CD using Jenkins and BitBucket - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"Integrate your Jenkins Server with Bitbucket to automate the process of CI\/CD and simplify the entire workflow. Trigger Jenkins Job via Bitbucket webhook.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-10T07:28:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-10-24T10:38:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/bitadffwefwf-300x92.png\" \/>\n<meta name=\"author\" content=\"Ayush Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/\",\"name\":\"CI\/CD using Jenkins and BitBucket - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2019-10-10T07:28:59+00:00\",\"dateModified\":\"2019-10-24T10:38:52+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/bc944fcbc7bf57b5c555d7b088523f1b\"},\"description\":\"Integrate your Jenkins Server with Bitbucket to automate the process of CI\/CD and simplify the entire workflow. Trigger Jenkins Job via Bitbucket webhook.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CI\/CD using Jenkins and BitBucket\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/bc944fcbc7bf57b5c555d7b088523f1b\",\"name\":\"Ayush Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6c01625f859badb9f845442bb4179cde?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6c01625f859badb9f845442bb4179cde?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"Ayush Singh\"},\"url\":\"https:\/\/cloudkul.com\/blog\/author\/ayushsingh-cloud332\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CI\/CD using Jenkins and BitBucket - Cloudkul","description":"Integrate your Jenkins Server with Bitbucket to automate the process of CI\/CD and simplify the entire workflow. Trigger Jenkins Job via Bitbucket webhook.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/","og_locale":"en_US","og_type":"article","og_title":"CI\/CD using Jenkins and BitBucket - Cloudkul","og_description":"Integrate your Jenkins Server with Bitbucket to automate the process of CI\/CD and simplify the entire workflow. Trigger Jenkins Job via Bitbucket webhook.","og_url":"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/","og_site_name":"Cloudkul","article_published_time":"2019-10-10T07:28:59+00:00","article_modified_time":"2019-10-24T10:38:52+00:00","og_image":[{"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2019\/10\/bitadffwefwf-300x92.png"}],"author":"Ayush Singh","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/","url":"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/","name":"CI\/CD using Jenkins and BitBucket - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2019-10-10T07:28:59+00:00","dateModified":"2019-10-24T10:38:52+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/bc944fcbc7bf57b5c555d7b088523f1b"},"description":"Integrate your Jenkins Server with Bitbucket to automate the process of CI\/CD and simplify the entire workflow. Trigger Jenkins Job via Bitbucket webhook.","breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/ci-cd-using-jenkins-and-bitbucket\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"CI\/CD using Jenkins and BitBucket"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/bc944fcbc7bf57b5c555d7b088523f1b","name":"Ayush Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6c01625f859badb9f845442bb4179cde?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6c01625f859badb9f845442bb4179cde?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"Ayush Singh"},"url":"https:\/\/cloudkul.com\/blog\/author\/ayushsingh-cloud332\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/4324"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=4324"}],"version-history":[{"count":72,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/4324\/revisions"}],"predecessor-version":[{"id":4758,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/4324\/revisions\/4758"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=4324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=4324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=4324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}