{"id":2550,"date":"2017-05-27T14:22:23","date_gmt":"2017-05-27T14:22:23","guid":{"rendered":"http:\/\/cloudkul.com\/blog\/?p=2550"},"modified":"2017-06-20T11:42:45","modified_gmt":"2017-06-20T11:42:45","slug":"magento2-continuous-integration-continuous-deployment-using-jenkins","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/","title":{"rendered":"Magento2 Continuous Integration and Continuous Deployment using Jenkins"},"content":{"rendered":"<p>In <strong>Continuous Integration<\/strong> and <strong>Continuous Deployment<\/strong> environment, there are many steps involved while deploying codes to the production server. Some of these steps are as follows-:<\/p>\n<ul>\n<li>Developers push their latest codes to the repository<\/li>\n<li>Code is fetched from the repository and built is made<\/li>\n<li>The built code is deployed to the staging server<\/li>\n<li>In staging server, some test cases are run<\/li>\n<li>After passing the test cases, code is deployed to the production server<\/li>\n<\/ul>\n<p>Jenkins is a great tool which can be used\u00a0 to setup continuous integration and continuous deployment environment for Magento2.<\/p>\n<p>In this tutorial, I will show you how to setup a continuous integration and deployment environment for magento2 using magedeploy2. If you want to know more about the magedeployer2 visit this link <a href=\"https:\/\/github.com\/mwr\/magedeploy2-base.git\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/mwr\/magedeploy2-base.git<\/a><\/p>\n<p>I am using 4 servers in this setup<\/p>\n<ol>\n<li><strong>Git server<\/strong><\/li>\n<li><strong>Jenkins server<\/strong><\/li>\n<li><strong>Staging server<\/strong><\/li>\n<li><strong>Production server<\/strong><\/li>\n<\/ol>\n<p>Below is the architecture of my continuous integration and deployment environment<\/p>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/05\/jenkins-arch.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2561\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/05\/jenkins-arch.png\" alt=\"\" width=\"797\" height=\"451\" \/><\/a><\/p>\n<ul>\n<li>When code is pushed to the git repository job trigger is generated at Jenkins through web hooks.<\/li>\n<li>At first step Jenkins will setup build environment for magento2.<\/li>\n<li>In second step it will fetch latest code from the git repository and build the code.<\/li>\n<li>In third step the built code is deployed to the staging server.<\/li>\n<li>In last step the built code is deployed to the production server.<\/li>\n<\/ul>\n<h2><span style=\"color: #ff0000\"><strong>Setting up your production server<\/strong><\/span><\/h2>\n<p><strong>Install apache and php dependencies<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">sudo add-apt-repository ppa:ondrej\/php\r\nsudo apt-get update\r\nsudo apt-get install apache2 php7.0 php7.0-{curl,gd,mbstring,mcrypt,json,dom,intl,xsl,readline,bcmath,zip,soap}\r\nsudo apt-get install git zip realpath<\/pre>\n<p>In production server, user <strong>magento<\/strong> is running the apache service. So I need to change the user <strong>www-data<\/strong> to <strong>magento<\/strong> in the <strong>\/etc\/apache2\/envvars<\/strong> file<\/p>\n<pre class=\"lang:sh decode:true\">export APACHE_RUN_USER=magento\r\nexport APACHE_RUN_GROUP=magento\r\n<\/pre>\n<p><strong>Virtual Host configuration<\/strong><\/p>\n<p>Create a new file <strong>\/etc\/apache2\/sites-enabled\/magento.conf <\/strong>and add the following codes<\/p>\n<pre class=\"lang:default decode:true\">&lt;VirtualHost&gt;\r\n   ServerName mysite.com\r\n   DocumentRoot \/home\/magento\/www\/current\r\n   CustomLog \/var\/log\/apache2\/mysite_access.log combined\r\n   ErrorLog  \/var\/log\/apache2\/mysite_error.log\r\n   &lt;Directory \/home\/magento\/www&gt;\r\n      Options FollowSymLinks MultiViews\r\n      Require all granted\r\n      AllowOverride all\r\n   &lt;\/Directory&gt;\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p><strong>Download n98-magerun2<\/strong><\/p>\n<pre class=\"lang:default decode:true\">wget https:\/\/files.magerun.net\/n98-magerun2.phar\r\nchmod +x n98-magerun2.phar\r\nsudo cp n98-magerun2.phar \/usr\/local\/bin\/<\/pre>\n<p><strong>Install composer<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">php -r \"copy('https:\/\/getcomposer.org\/installer', 'composer-setup.php');\"\r\nphp -r \"if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;\"\r\nphp composer-setup.php\r\nchmod +x composer.phar \r\nmv composer.phar \/usr\/local\/bin\/composer<\/pre>\n<p><strong>Restart apache service<\/strong><\/p>\n<pre class=\"lang:default decode:true\">phpenmod mcrypt\r\nphpenmod mbstring\r\na2enmod rewrite\r\na2enmod php7.0\r\nservice apache2 restart<\/pre>\n<p><strong>Install mysql server<\/strong><\/p>\n<pre class=\"lang:default decode:true\">sudo apt-get install mysql-server-5.6<\/pre>\n<p><strong>create database and user for magento<\/strong><\/p>\n<p>Login to your root mysql user and create user and database<\/p>\n<pre class=\"lang:default decode:true\">mysql -u root -p\r\ncreate database production;\r\ncreate user 'dbuserprod'@'%' ideintified by 'qh3gf4ce';\r\ngrant all privileges on production.* to 'dbuserprod'@'%';<\/pre>\n<h2><span style=\"color: #ff0000\"><strong>Setting up your staging server<\/strong><\/span><\/h2>\n<p>Follow the same procedure as in the production server. Just make some changes in the virtual host configuration and database setup. In staging server user <strong>test <\/strong>is running apache service. Open <strong>\/etc\/apache2\/envvars<\/strong> file and change user <strong>www-data<\/strong> to <strong>test<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">export APACHE_RUN_USER=test\r\nexport APACHE_RUN_GROUP=test\r\n<\/pre>\n<p><strong>Virtual Host configuration<\/strong><\/p>\n<p>create a file <strong>\/etc\/apache2\/sites-enabled\/magento.conf<\/strong> and add the following content<\/p>\n<pre class=\"lang:sh decode:true\">&lt;VirtualHost&gt;\r\n   ServerName staging.mysite.com\r\n   DocumentRoot \/home\/test\/www\/current\r\n   CustomLog \/var\/log\/apache2\/mysite_access.log combined\r\n   ErrorLog  \/var\/log\/apache2\/mysite_error.log\r\n   &lt;Directory \/home\/test\/www&gt;\r\n      Options FollowSymLinks MultiViews\r\n      Require all granted\r\n      AllowOverride all\r\n   &lt;\/Directory&gt;\r\n&lt;\/VirtualHost&gt;\r\n\r\n<\/pre>\n<p><strong>create database and user for magento<\/strong><\/p>\n<p>Login to your root mysql user and create user and database<\/p>\n<pre class=\"lang:default decode:true\">mysql -u root -p\r\ncreate database staging;\r\ncreate user 'dbuserstage'@'%' ideintified by 'msdjo335s';\r\ngrant all privileges on staging.* to 'dbuserstage'@'%';\r\n<\/pre>\n<h2><span style=\"color: #ff0000\"><strong>Setting up your Jenkins server<\/strong><\/span><\/h2>\n<p><strong>create database and user for magento<\/strong><\/p>\n<pre class=\"lang:default decode:true\">mysql -u root -p\r\ncreate database build;\r\ncreate user 'dbuserbuild'@'%' ideintified by 'p0jhser847';\r\ngrant all privileges on build.* to 'dbuserbuild'@'%';\r\n\r\n<\/pre>\n<p>Download and setup composer as given in the production server setup.<\/p>\n<p><strong>create and login as non-root user <\/strong><\/p>\n<pre class=\"lang:sh decode:true\">adduser jenkins\r\nsu - jenkins<\/pre>\n<p><strong>Download magedeploy2-base<\/strong><\/p>\n<pre class=\"lang:default decode:true\">composer create-project mwltr\/magedeploy2-base magento2<\/pre>\n<p>create <strong>.config\/composer\/auth.json<\/strong> file and add your magento2 credential for <strong>repo.magento.com<\/strong><\/p>\n<pre class=\"lang:js decode:true\">{\r\n    \"http-basic\": {\r\n        \"repo.magento.com\": {\r\n                        \"username\": \"&lt;Enter your key here&gt;\",\r\n                        \"password\": \"&lt;Enter your key here&gt;\"\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>create your default <strong>magedeploy2.php<\/strong>, <strong>staging.php<\/strong> and <strong>production.php<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">mkdir site\r\ntouch site\/magedeploy2.php\r\ntouch site\/staging.php\r\ntouch site\/production.php\r\ntouch site\/config\r\ncp -rv magento2\/vendor\/n98\/n98-deployer\/src\/Deployer\/Task site\/<\/pre>\n<p>change the content of the files according to your need. Every time you run the Jenkins job the defaults php files inside <strong>site<\/strong> folder will be used for the build and deployment tasks.<\/p>\n<p><strong>magedeploy2.php<\/strong><\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\nreturn [\r\n    'env' =&gt; [\r\n        'git_bin' =&gt; getenv('GIT_BIN') ?: '\/usr\/bin\/git',\r\n        'php_bin' =&gt; getenv('PHP_BIN') ?: '\/usr\/bin\/php',\r\n        'tar_bin' =&gt; getenv('TAR_BIN') ?: '\/bin\/tar',\r\n        'mysql_bin' =&gt; getenv('MYSQL_BIN') ?: '\/usr\/bin\/mysql',\r\n        'composer_bin' =&gt; getenv('COMPOSER_BIN') ?: '\/usr\/local\/bin\/composer',\r\n        'deployer_bin' =&gt; getenv('DEPLOYER_BIN') ?: '\/home\/jenkins\/magento2\/vendor\/bin\/dep',\r\n    ],\r\n    'deploy' =&gt; [\r\n        'git_url' =&gt; 'https:\/\/username:password@mygitrepo.com\/repo1\/magedeploy.git',\r\n        'git_dir' =&gt; 'shop',\r\n        'app_dir' =&gt; 'shop',\r\n        'artifacts_dir' =&gt; 'artifacts',\r\n        'themes' =&gt; [\r\n            ['code' =&gt; 'Magento\/backend','languages' =&gt; ['en_US','de_DE']],\r\n['code' =&gt; 'Magento\/luma','languages' =&gt; ['de_DE']],\r\n['code' =&gt; 'Magento\/luma','languages' =&gt; ['en_US']],\r\n        ],\r\n        'artifacts' =&gt; [\r\n            'shop.tar.gz' =&gt; ['dir' =&gt; '.','options' =&gt; ['--exclude-vcs','--checkpoint=5000']],\r\n        ],\r\n        'clean_dirs' =&gt; [\r\n            'var\/cache',\r\n            'var\/di',\r\n            'var\/generation',\r\n        ],\r\n    ],\r\n    'build' =&gt; [\r\n        'db' =&gt; [\r\n            'db-host' =&gt; getenv('DB_HOST') ?: '127.0.0.1',\r\n            'db-name' =&gt; getenv('DB_NAME') ?: 'build',\r\n            'db-user' =&gt; getenv('DB_USER') ?: 'dbuserbuild',\r\n            'db-password' =&gt; getenv('DB_PASSWORD') ?: 'p0jser847',\r\n            'admin-email' =&gt; 'suranjan.horrow869@webkul.com',\r\n            'admin-firstname' =&gt; 'Suranjan',\r\n            'admin-lastname' =&gt; 'Horrow',\r\n            'admin-password' =&gt; 'dswe234532r',\r\n            'admin-user' =&gt; 'admin',\r\n            'backend-frontname' =&gt; 'admin',\r\n            'base-url' =&gt; 'http:\/\/mysite.com',\r\n            'base-url-secure' =&gt; 'https:\/\/mysite.com',\r\n            'currency' =&gt; 'EUR',\r\n            'language' =&gt; 'en_US',\r\n            'session-save' =&gt; 'files',\r\n            'timezone' =&gt; 'Asia\/Kolkata',\r\n            'use-rewrites' =&gt; '1',\r\n            'use-secure' =&gt; '0',\r\n            'use-secure-admin' =&gt; '0',\r\n        ],\r\n    ],\r\n];\r\n<\/pre>\n<p>I am using <strong>https:\/\/username:password@mygitrepo.com\/repo1\/magedeploy.git <\/strong>in git url because I do not want prompt for <strong>username<\/strong> and <strong>password<\/strong> while cloning from git. We are providing the username and password in the url. So it will be easy for the automation process.<\/p>\n<p>Here, <strong>https:\/\/mygitrepo.com\/repo1\/magedeploy.git <\/strong>is your actual git url for your repo.<\/p>\n<p><strong>staging.php<\/strong><\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\n\/**\r\n * @copyright Copyright (c) 2017 Matthias Walter\r\n * @copyright Copyright (c) 2017 netz98 GmbH (http:\/\/www.netz98.de)\r\n *\r\n * @see LICENSE\r\n *\/\r\n\r\n\r\nnamespace Deployer;\r\n\r\nuse N98\\Deployer\\RoleManager;\r\n$deployPath = '\/home\/test\/www';\r\n$staging = host('192.168.1.67'); \/\/ IP of the staging server\r\n$staging-&gt;set('bin\/n98_magerun2', 'n98-magerun2.phar');\r\n$staging-&gt;user('test'); \/\/ user of the staging server\r\n$staging-&gt;configFile('.ssh\/config');\r\n$staging-&gt;set('deploy_path', $deployPath);\r\n$staging-&gt;stage('staging');\r\n$staging-&gt;set('config_store_env', 'staging');\r\n$staging-&gt;roles('web','db','staging');\r\n<\/pre>\n<p><strong>production.php<\/strong><\/p>\n<pre class=\"lang:php decode:true \">&lt;?php\r\n\/**\r\n * @copyright Copyright (c) 2017 Matthias Walter\r\n * @copyright Copyright (c) 2017 netz98 GmbH (http:\/\/www.netz98.de)\r\n *\r\n * @see LICENSE\r\n *\/\r\n\r\n\r\nnamespace Deployer;\r\n\r\nuse N98\\Deployer\\RoleManager;\r\n\r\n$deployPath = '\/home\/magento\/www';\r\n$sshConfigFile = '.ssh\/config';\r\n$production = host('192.168.1.113');  \/\/ IP of the production server\r\n$production-&gt;set('bin\/n98_magerun2', 'n98-magerun2.phar');\r\n$production-&gt;user('magento'); \/\/ user of the production server\r\n$production-&gt;configFile($sshConfigFile);\r\n$production-&gt;set('deploy_path', $deployPath);\r\n$production-&gt;stage('production');\r\n$production-&gt;set('config_store_env', 'production');\r\n$production-&gt;roles('web','db','production');\r\n<\/pre>\n<p><strong>config<\/strong><\/p>\n<pre class=\"lang:default decode:true\">StrictHostKeyChecking no\r\n    ControlMaster auto\r\n    ControlPath ~\/tmp\/ssh-mux-%h-%p-%r\r\n<\/pre>\n<p>The files <strong>inside \/home\/testuser\/site\/Task<\/strong> are<\/p>\n<ul>\n<li>BuildTasks.php<\/li>\n<li>CleanupTasks.php<\/li>\n<li>DeployTasks.php<\/li>\n<li>MagentoTasks.php<\/li>\n<li>SystemTasks.php<\/li>\n<li>TaskAbstract.php<\/li>\n<\/ul>\n<p>Some of the tasks required sudo access. So it will be difficult for us to automate the process because it will ask for password when sudo access is needed. We will remove sudo related tasks in these files.<\/p>\n<p>In <strong>BuildTasks.php<\/strong> comment these lines<\/p>\n<pre class=\"lang:php decode:true\">            #\\Deployer\\run(\"sudo chown -RH $owner $dir\");\r\n            #\\Deployer\\run(\"sudo chmod -R $mode $dir\");\r\n<\/pre>\n<p>In <strong>CleanupTasks.php<\/strong> remove sudo<\/p>\n<pre class=\"lang:php decode:true\">\\Deployer\\run(\"rm -rf {{deploy_path}}\/releases\/$release\");\r\n<\/pre>\n<p>In <strong>SystemTasks.php\u00a0\u00a0<\/strong>comment these lines<\/p>\n<pre class=\"lang:php decode:true\"> #\\Deployer\\run(\"sudo service $service restart\");\r\n #\\Deployer\\run(\"sudo service $service restart\");\r\n<\/pre>\n<p>If your\u00a0 user in staging and production server has sudo access you do not need to edit these files.<\/p>\n<p><strong>Create password less authentication from Jenkins server to staging and production server<\/strong><\/p>\n<p>Go to home directory of user <strong>jenkins<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">ssh-copy-id test@192.168.1.67  # staging server\r\nssh-copy-id magento@192.168.1.113 # production server<\/pre>\n<p>Now, you can execute command on remote server without password<\/p>\n<p><strong>Create scripts for running deploy tasks<\/strong><\/p>\n<p>I have created 4 scripts for deploying Magento<\/p>\n<ol>\n<li><strong>setup.sh<\/strong><\/li>\n<li><strong>build.sh<\/strong><\/li>\n<li><strong>stage.sh<\/strong><\/li>\n<li><strong>prod.sh<\/strong><\/li>\n<\/ol>\n<p><strong>setup.sh<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">#!\/bin\/bash\r\nset -ex\r\nif [ -d \/home\/jenkins\/magento2 ]\r\nthen\r\n    rm -rf magento2\r\nfi\r\ncomposer create-project mwltr\/magedeploy2-base magento2\r\n<\/pre>\n<p><strong>build.sh<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">#!\/bin\/bash\r\nset -ex\r\ncp site\/magedeploy2.php magento2\/\r\ncd \/home\/jenkins\/magento2\r\n.\/vendor\/bin\/robo validate\r\n.\/vendor\/bin\/robo deploy:magento-setup master\r\n.\/vendor\/bin\/robo deploy:artifacts-generate\r\n<\/pre>\n<p><strong>stage.sh<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">#!\/bin\/bash\r\nset -ex\r\ncd \/home\/jenkins\/magento2\r\ncp ..\/site\/staging.php config\/\r\ncp ..\/site\/config .ssh\/\r\ncp -rv ..\/site\/Task vendor\/n98\/n98-deployer\/src\/Deployer\/\r\n.\/vendor\/bin\/dep deploy:prepare staging\r\n.\/vendor\/bin\/dep server:setup staging\r\nssh test@192.168.1.67 php \/home\/test\/www\/current\/bin\/magento setup:install --db-host=\"127.0.0.1\" --db-name=\"staging\" --db-user=\"dbuserstage\" --admin-email=\"suranjan.horrow869@webkul.com\" --db-password=\"msdjo335s\" --admin-firstname=\"Suranjan\" --admin-lastname=\"Horrow\" --admin-password=\"webkul123\" --admin-user=\"admin\" --backend-frontname=\"admin\" --base-url=\"http:\/\/staging.mysite.com\/\" --base-url-secure=\"https:\/\/staging.mysite.com\/\"  --language=\"en_US\"  --use-rewrites=1\r\ncd \/home\/jenkins\/magento2\r\n.\/vendor\/bin\/dep deploy staging\r\n<\/pre>\n<p><strong>prod.sh<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">#!\/bin\/bash\r\nset -ex\r\ncd \/home\/jenkins\/magento2\r\ncp ..\/site\/production.php config\/\r\ncp ..\/site\/config .ssh\/\r\ncp -rv ..\/site\/Task vendor\/n98\/n98-deployer\/src\/Deployer\/\r\n.\/vendor\/bin\/dep deploy:prepare production\r\n.\/vendor\/bin\/dep server:setup production\r\nssh magento@192.168.1.113 php \/home\/magento\/www\/current\/bin\/magento setup:install --db-host=\"192.168.1.113\" --db-name=\"production\" --db-user=\"dbuserprod\" --admin-email=\"suranjan.horrow869@webkul.com\" --db-password=\"qh3gf4ce\" --admin-firstname=\"Suranjan\" --admin-lastname=\"Horrow\" --admin-password=\"webkul123\" --admin-user=\"admin\" --backend-frontname=\"admin\" --base-url=\"http:\/\/mysite.com\/\" --base-url-secure=\"https:\/\/mysite.com\/\"  --language=\"en_US\"  --use-rewrites=1\r\ncd \/home\/jenkins\/magento2\r\n.\/vendor\/bin\/dep deploy production\r\n<\/pre>\n<p>Now we need to execute these shell scripts through Jenkins pipeline.<\/p>\n<p><strong>Create pipeline jobs in Jenkins<\/strong><\/p>\n<p>Login to your admin panel in Jenkins.<\/p>\n<p>Go to <strong>New Item<\/strong> -&gt; <strong>Pipeline<\/strong><\/p>\n<p>Create a name for your pipeline and your job will be created.<\/p>\n<p>Then got to <strong>Build Triggers<\/strong> and select <strong>Trigger builds remotely<\/strong>. Give your Authentication Token. The <strong>Authentication<\/strong> <strong>Token<\/strong> will be used in git webhook.<\/p>\n<p>In Pipeline script copy the following codes.<\/p>\n<pre class=\"lang:default decode:true\">node('master') {\r\n        stage('Set up') \r\n                sh 'su - jenkins -c \"bash setup.sh\"'\r\n        stage('Build') \r\n                sh 'su - jenkins -c \"bash build.sh\"'\r\n        stage('Deploy staging') \r\n                sh 'su - jenkins -c \"bash stage.sh\"'\r\n        stage('Deploy  production') \r\n                sh 'su - jenkins -c \"bash prod.sh\"'\r\n            \r\n    }<\/pre>\n<p>In this pipeline script we are defining 4 stages. If one of the stage is failed, the Jenkins job will be stopped.<\/p>\n<p>Now, save your Jenkins pipeline job.<\/p>\n<h2><span style=\"color: #ff0000\"><strong>Setting up your git repository<\/strong><\/span><\/h2>\n<p>Create a repository for magento2. We will upload our files in this repository.<\/p>\n<p>Now go to <strong>Settings<\/strong> of this repo and select <strong>Web hooks<\/strong><strong>.<\/strong> Write the url you want to trigger when someone pushes the code into git.<\/p>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/05\/git-webhook.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2570\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/05\/git-webhook.png\" alt=\"\" width=\"1262\" height=\"586\" \/><\/a><\/p>\n<p>When someone pushes the code <strong>http:\/\/example.com\/hook.php<\/strong> will be called. In hook.php I am executing a curl command which will trigger the Jenkins job we have previously defined.<\/p>\n<p><strong>hook.php<\/strong><\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\nshell_exec('curl http:\/\/user:pass@192.168.1.94:8080\/jenkins\/job\/deploy_magento\/build?token=sgfed35e3d2');\r\n?&gt;\r\n<\/pre>\n<p>In this code <strong>user<\/strong> and <strong>pass<\/strong> is the username and password of Jenkins admin user. The job name is <strong>deploy_magento<\/strong> and\u00a0<strong>sgfed35e3d2<\/strong> is the Authentication Token we defined at the creation of the Jenkins Job.<\/p>\n<p>Now, we have completed setting up our server. For installing magento2 upload magento2 setup files in the git repository. This will trigger the job defined in Jenkins. Job will start automatically and start executing the scripts. When the job is completed you can visit your staging server and production server in the browser. If you want to install modules in magento2, just push your module codes to the git repository and it will be automatically tested and deployed to the production server.<\/p>\n<p><a href=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/05\/jenkins-pipeline.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2572\" src=\"http:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/05\/jenkins-pipeline.png\" alt=\"\" width=\"1274\" height=\"627\" \/><\/a><\/p>\n<p>If your job failed for some reason, you can check the <strong>build logs<\/strong>. This is all about setting up <strong>Continuous Integration<\/strong> and <strong>Continuous Deployment<\/strong> environment for magento2. If you have any query regarding the setup procedure, 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\" rel=\"noopener noreferrer\">IN CASE OF ANY QUERY, CONTACT US<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Continuous Integration and Continuous Deployment environment, there are many steps involved while deploying codes <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":8,"featured_media":2574,"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],"tags":[169,171,170,94,24],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento2 Continuous Integration and Continuous Deployment using 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\/magento2-continuous-integration-continuous-deployment-using-jenkins\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento2 Continuous Integration and Continuous Deployment using Jenkins - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"In Continuous Integration and Continuous Deployment environment, there are many steps involved while deploying codes [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2017-05-27T14:22:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-06-20T11:42:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/05\/jenkins-ci-cd.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\/magento2-continuous-integration-continuous-deployment-using-jenkins\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/\",\"name\":\"Magento2 Continuous Integration and Continuous Deployment using Jenkins - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2017-05-27T14:22:23+00:00\",\"dateModified\":\"2017-06-20T11:42:45+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/a653191c790a89b07d4b4aaefc3e2809\"},\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento2 Continuous Integration and Continuous Deployment using 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":"Magento2 Continuous Integration and Continuous Deployment using 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\/magento2-continuous-integration-continuous-deployment-using-jenkins\/","og_locale":"en_US","og_type":"article","og_title":"Magento2 Continuous Integration and Continuous Deployment using Jenkins - Cloudkul","og_description":"In Continuous Integration and Continuous Deployment environment, there are many steps involved while deploying codes [...]","og_url":"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/","og_site_name":"Cloudkul","article_published_time":"2017-05-27T14:22:23+00:00","article_modified_time":"2017-06-20T11:42:45+00:00","og_image":[{"width":848,"height":422,"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2017\/05\/jenkins-ci-cd.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\/magento2-continuous-integration-continuous-deployment-using-jenkins\/","url":"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/","name":"Magento2 Continuous Integration and Continuous Deployment using Jenkins - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2017-05-27T14:22:23+00:00","dateModified":"2017-06-20T11:42:45+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/a653191c790a89b07d4b4aaefc3e2809"},"breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/magento2-continuous-integration-continuous-deployment-using-jenkins\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento2 Continuous Integration and Continuous Deployment using 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\/2550"}],"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=2550"}],"version-history":[{"count":34,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/2550\/revisions"}],"predecessor-version":[{"id":2979,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/2550\/revisions\/2979"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media\/2574"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=2550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=2550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=2550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}