Jenkins template for continuous integration for Drupal Multi Site

You, Jenkins
Back

We've been working on implementing continuous integration for our projects to improve code quality. In the process we've built a template which should make it easy to setup CI for new projects and want to share these with the community. Hopefully you'll find it useful!.

These are for multi site but you can figure ont how it use it for a single site.

Requirements

PHP

Using the template requires a phing PEAR packages present. They can be installed as follows:

pear channel-discover pear.phing.info
pear install phing/phing-2.4.12

Jenkins

Phing (for running Phing build files)

build.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- creates a clean build,
     symlinks a webdir for each site,
     sets up settings.php,
     symlinks files+settings.php
     for each site (uses multisite to make it work transparently for the devs) -->
<project name="Multisite Project" default="deploy">
  <tstamp>
    <format property="NOW" pattern="%Y%m%d%H%M%S" />
  </tstamp>
  <property name="source\_dir" value="./" />
  <property name="build\_destination" value="/opt/jenkins/PROJECTNAME${NOW}" />
  <taskdef name="symlink" classname="phing.tasks.ext.SymlinkTask" />
  <target name="build">
    <!-- copy checkout into our build directory -->
    <copy todir="${build\_destination}">
      <fileset dir="${source\_dir}">
        <exclude name=".git" />
        <exclude name=".git/\*\*" />
        <exclude name="build.xml" />
      </fileset>
    </copy>
  </target>
  <target name="deploy" depends="build">
    <!-- common settings -->
    <!-- <property name="username" value="USERNAME" />  -->
    <property name="web\_dir" value="/var/www/PROJECTNAME" />
    <delete file="${web\_dir}/htdocs" />
    <symlink target="${build\_destination}" link="${web\_dir}/htdocs" />

    <!-- SITE 1 -->
    <property name="username" value="USERNAME" />
    <property name="password" value="PASSWORD" />
    <property name="databasename" value="DBNAME" />
    <copy file="${build\_destination}/sites/default/default.settings.php" tofile="${build\_destination}/sites/SITE1/settings.php">
      <filterchain>
        <replacetokens>
          <token key="databasename" value="${databasename}" />
          <token key="username" value="${username}" />
          <token key="password" value="${password}" />
        </replacetokens>
      </filterchain>
    </copy>
    <symlink target="/opt/files/SITE1/files" link="${build\_destination}/sites/SITE1/files" />

    <!-- SITE2 -->
    <property name="username" override="yes" value="USERNAME" />
    <property name="password" override="yes" value="PASSWORD" />
    <property name="databasename" override="yes" value="DBNAME" />
    <copy file="${build\_destination}/sites/default/default.settings.php" tofile="${build\_destination}/sites/SITE2/settings.php">
      <filterchain>
        <replacetokens>
          <token key="databasename" value="${databasename}" />
          <token key="username" value="${username}" />
          <token key="password" value="${password}" />
        </replacetokens>
      </filterchain>
    </copy>
    <symlink target="/opt/files/SITE2/files" link="${build\_destination}/sites/SITE2/files" />

  </target>
</project>

default.settings.php - Change the $databases as follow.

 $databases\['default'\]\['default'\] = array(
   'driver' => 'mysql',
   'database' => '@databasename@',
   'username' => '@username@',
   'password' => '@password@',
   'host' => 'localhost',
   'prefix' => '',
 );
© Heshan Wanigasooriya.RSS

🍪 This site does not track you.