{"id":1664,"date":"2017-01-04T12:39:42","date_gmt":"2017-01-04T12:39:42","guid":{"rendered":"http:\/\/cloudkul.com\/blog\/?p=1664"},"modified":"2017-06-14T11:33:34","modified_gmt":"2017-06-14T11:33:34","slug":"magento-integration-jenkins","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/","title":{"rendered":"Magento  Integration with Jenkins"},"content":{"rendered":"<p>Before deploying codes to the production server, the codes need to be fully tested. Testers check the codes by running different test cases. It is a very long process. First the developers push their codes to the repository. Then the testers fetch the codes and run the codes in their own environment. If something wrong with the codes, they notify it to the developers. Developers fix their codes and again push it to the repository. Codes are not deployed to the production server unless they pass the test cases.<\/p>\n<p>Jenkins can automate the whole process and save time required by manual testing. Testers can set their test cases in the Jenkins Job. The testing job can be triggered any time. Tester can set a fix time when the job will be triggered. For example Tester can set 9 p.m for job to be started. So at 9 p.m Jenkins will fetch the code from the repository and run the test and tell every one the result. Testers do not have to manually fetch the code and copy in their testing environment and finally test it. Jenkins will do the job in a sequence.<\/p>\n<p>In this tutorial, I will show you how to setup a automated testing job in Jenkins. It will fetch module codes from repository and install the module in the existinging magento server.<\/p>\n<p>I am using ant to use in the build process. Ant will read <strong>build.xml<\/strong> file and perform action according to the file.<\/p>\n<p>Suppose, my git repository is\u00a0<strong>http:\/\/192.168.1.210\/suranjan\/magento-extension.git<\/strong>. So I will put my <strong>build.xml<\/strong> file in the repository. I have already setup a magento server. When the build is triggered, then Jenkins will fetch contents from git repository and copy the files in the magento server and run some commands to install the module.<\/p>\n<p>Below is the <strong>build.xml<\/strong> file. I have divided the tasks in 4 parts. First part will fetch the files and copy it to the magento server. Next two part it will execute some command in magento server and at last <strong>casperjs<\/strong> will run some test cases.<\/p>\n<pre class=\"lang:sh decode:true\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;project name=\"php testing\" default=\"run task\"&gt;\r\n    &lt;property name=\"basedir\" value=\".\" \/&gt;\r\n\r\n    &lt;target name=\"fetch\" description=\"copy extension to test server\"&gt;\r\n         &lt;exec executable=\"rsync\" failonerror=\"true\"&gt;\r\n              &lt;arg line=\"-rv app\/ user@192.168.5.121:\/home\/linux\/www\/app\/\" \/&gt;\r\n         &lt;\/exec&gt;\r\n   &lt;\/target&gt;\r\n   &lt;target name=\"upgrade\" description=\"set up and upgrade\"&gt;\r\n         &lt;exec executable=\"ssh\" failonerror=\"true\"&gt;\r\n              &lt;arg line=\"user@192.168.5.121 php www\/bin\/magento setup:upgrade\" \/&gt;\r\n         &lt;\/exec&gt;\r\n   &lt;\/target&gt;\r\n   &lt;target name=\"deploy\" description=\"set up and upgrade\"&gt;\r\n         &lt;exec executable=\"ssh\" failonerror=\"true\"&gt;\r\n              &lt;arg line=\"user@192.168.5.121 php www\/bin\/magento setup:static-content:deploy\" \/&gt;\r\n         &lt;\/exec&gt;\r\n   &lt;\/target&gt;\r\n   &lt;target name=\"casperjs\" description=\"Run casperjs\"&gt;\r\n         &lt;exec executable=\"ssh\" failonerror=\"true\"&gt;\r\n              &lt;arg line=\"user@192.168.5.121 casperjs sample.js\" \/&gt;\r\n         &lt;\/exec&gt;\r\n   &lt;\/target&gt;\r\n   &lt;target name=\"run task\" description=\"Run target one by one\"&gt;\r\n      &lt;sequential&gt;\r\n         &lt;antcall target=\"fetch\" \/&gt;\r\n         &lt;antcall target=\"upgrade\" \/&gt;\r\n         &lt;antcall target=\"deploy\" \/&gt;\r\n         &lt;antcall target=\"casperjs\" \/&gt;\r\n      &lt;\/sequential&gt;\r\n   &lt;\/target&gt;\r\n&lt;\/project&gt;<\/pre>\n<p>I have already copied the public key in the target magento server, so when I run the commands remotely it will not ask for any password.<\/p>\n<p><strong>Create a Job in Jenkins<\/strong><\/p>\n<p>Open Jenkins dashboard and select <strong>New Item.<\/strong><\/p>\n<p>Select Freestyle project and choose a job name.<\/p>\n<p>In source code management select <strong>git<\/strong> and give your repository url. If your repository is private provide the credential.<\/p>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/jenkins-git.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1675\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/jenkins-git.png\" alt=\"\" width=\"984\" height=\"507\" \/><\/a><\/p>\n<p>In <strong>Build Triggers<\/strong> select how you want to trigger the build. If you want to do it manually you can leave the fields.<\/p>\n<p>In <strong>Build Environment<\/strong> select <strong>Delete workspace before build starts<\/strong><\/p>\n<p>In <strong>add build step\u00a0<\/strong>select <strong>invoke ant.\u00a0<\/strong>In <strong>Build File<\/strong>\u00a0parameter write <strong>build.xml.\u00a0<\/strong><\/p>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/jenkins-ant.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1677\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/jenkins-ant.png\" alt=\"\" width=\"998\" height=\"413\" \/><\/a><\/p>\n<p>In <strong>post-build<\/strong> actions select <strong>E-mail notification<\/strong> and give recipients email address. If the build is unsuccessful, mail will be sent to the given recipients.<\/p>\n<p>After setting up all the parameters save the configuration. I have successfully created a job. Now it&#8217;s time to trigger the job. Go to Jenkins dashboard and select your job. click <strong>Build Now.\u00a0<\/strong>After that build process will be start. You can view the ongoing build process through the output console.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/jenkins-log.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1692\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/jenkins-log.png\" alt=\"\" width=\"772\" height=\"550\" \/><\/a><\/p>\n<p>If you want to detect where the build failed, you can view it in the console output.\u00a0If you have any doubts regarding the setup, you can ask me in the comment.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/cloudkul.com\/contact\/\" target=\"_blank\"> IN CASE OF ANY QUERY,CONTACT US<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before deploying codes to the production server, the codes need to be fully tested. Testers <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":8,"featured_media":1696,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[20,1],"tags":[94,24],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento Integration with Jenkins - Cloudkul<\/title>\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\/magento-integration-jenkins\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento Integration with Jenkins - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"Before deploying codes to the production server, the codes need to be fully tested. Testers [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-04T12:39:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-06-14T11:33:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/magento-jenkins-banner.png\" \/>\n\t<meta property=\"og:image:width\" content=\"848\" \/>\n\t<meta property=\"og:image:height\" content=\"422\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"suranjan horrow\" \/>\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\/magento-integration-jenkins\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/\",\"name\":\"Magento Integration with Jenkins - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2017-01-04T12:39:42+00:00\",\"dateModified\":\"2017-06-14T11:33:34+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/a653191c790a89b07d4b4aaefc3e2809\"},\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento Integration with Jenkins\"}]},{\"@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\/a653191c790a89b07d4b4aaefc3e2809\",\"name\":\"suranjan horrow\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dfd7f87bc7d62c1426e1f4c07653ff00?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dfd7f87bc7d62c1426e1f4c07653ff00?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"suranjan horrow\"},\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/cloudkul.com\/blog\/author\/suranjan-horrow869\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento Integration with Jenkins - Cloudkul","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\/magento-integration-jenkins\/","og_locale":"en_US","og_type":"article","og_title":"Magento Integration with Jenkins - Cloudkul","og_description":"Before deploying codes to the production server, the codes need to be fully tested. Testers [...]","og_url":"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/","og_site_name":"Cloudkul","article_published_time":"2017-01-04T12:39:42+00:00","article_modified_time":"2017-06-14T11:33:34+00:00","og_image":[{"width":848,"height":422,"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/01\/magento-jenkins-banner.png","type":"image\/png"}],"author":"suranjan horrow","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/","url":"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/","name":"Magento Integration with Jenkins - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2017-01-04T12:39:42+00:00","dateModified":"2017-06-14T11:33:34+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/a653191c790a89b07d4b4aaefc3e2809"},"breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/magento-integration-jenkins\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento Integration with Jenkins"}]},{"@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\/a653191c790a89b07d4b4aaefc3e2809","name":"suranjan horrow","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dfd7f87bc7d62c1426e1f4c07653ff00?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dfd7f87bc7d62c1426e1f4c07653ff00?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"suranjan horrow"},"sameAs":["http:\/\/webkul.com"],"url":"https:\/\/cloudkul.com\/blog\/author\/suranjan-horrow869\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/1664"}],"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\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=1664"}],"version-history":[{"count":14,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/1664\/revisions"}],"predecessor-version":[{"id":1695,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/1664\/revisions\/1695"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media\/1696"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=1664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=1664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=1664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}