CMS

Drupal Continuous integration with Jenkins

Main Motive of continuous integration is to eliminate the manual errors and get instant feedback on the quality of the code commits.
Drupal CI decreases the time taken for the build deployment and it follows the same process to deploy across all the environments. And this will help us to decrease the numbers of errors and have stable sites across the environments
Drupal Ci Checks the code quality/ Security to each build and give the instant results and report of the site security and standards.
Drupal Ci helps us achieve Continuous deployment of Code to all the stages of the environment (Development, QA and Production)
Prerequisite’s for the Drupal Host server:
1.    Php 7+
2.    Drush 8+
3.    MariaDB/Mysql
4.    Apache
5.    Source Control (GIT)
Operating System –  Centos 7
Installing PHP 7 On centos OS:
Add the below repository to the centos 7 to get the Php 7 through yum
Login to the server using ssh and copy and paste the below commands in the putty
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

To install Php 7 run the below commands:
yum install php70w php70w-opcache
yum install php70w*

Installing Drush 8 on centos :

Installing drush latest version use the below commands:

sudo yum install php-pear
pear channel-discover pear.drush.org
pear install drush/drush

To install to specific version of drush use the below commands, in the below commands I have used drush version 5.9
sudo yum install php-pear
pear channel-discover pear.drush.org
pear install drush/drush-5.9.0

Installing MariaDB on Centos 7:
Run the below command to download and install mariadb using yum
sudo yum install mariadb-server

Enabling Mariadb service to start during the system boot run the below command
sudo systemctl enable mariadb
To start the mariadb service run the below command
sudo systemctl start mariadb

Installing Apache on Centos 7:
Run the below command to download and install httpd (apache) in the server
Yum install httpd
Creating the Git repo in the git lab server:
Login to the git lab server and create a new project and upload the drupal code to the Git project

Give the project name and click on create project.
Download the required drupal version from the https://www.drupal.org/project/download
And upload the extracted code to the git project.
Create a Jenkins job to deploy the drupal to the server using Jenkins

Select the source code management as git and give the repository URL as git url, if you want to specify any branch you can specify in the branch specifier “*/Branch name”

Select the option build when the change is pushed to gitlab
In enabled Build triggers select for only “Push Events” so that whenever a change is pushed to the git build triggers
To achieve this, you need to copy the Secret token and configure it in the git lab integrations webhooks,
As shown in the below screen given the URL of the Jenkins and secret token and select push events and click on add webhook.

 

In the Build process select Execute shell and give all the below commands in the shell
Sync the code from Jenkins work space to website directory by using the below command if you want to sync the code to remote server need to ssh private key to the local system and change the below command in the destination as root@192.168.xx.xx:/var/www/html
rsync -auvz /var/lib/jenkins/workspace/drupal/ /var/www/html –delete
Giving permission to apache to /var/www/html/sites/default/files as the dynamic content is created by drupal for the site
chown -R apache:apache /var/www/html/sites/default/files
Changing the permissions of settings.php file to 444 as the users logged in to the server does not change any configuration
chmod -R 444 /var/www/html/sites/default/settings.php
Clearing the cache of the drush
drush cc drush -r /var/www/html/
Updates the Db if there are any new modules enabled from the code
drush updb -r /var/www/html –y
Clearing the cache of the site
drush cc all -r /var/www/html

Add a build step Review code in drupal and select the required things as show below

Will send email if the build is gets failed


The same steps need to be followed for all other environment.

About The Author

Leave a Reply

*