Accueil / Blog / Métier / Archives / Drupal and Jenkins: continuous integration howto

Drupal and Jenkins: continuous integration howto

Par Benoit Bryon — publié 07/12/2011, édité le 14/04/2016

Once you know how to run tests with Drupal [1], you'd like some automation...

Here is a recipe to set up a continuous integration service for Drupal, using the well-known Jenkins [2] software.

Prerequisites: system setup

You need:

  • a Jenkins server. Python users may use the jarn.jenkins [3] recipe for buildout;
  • a Drupal 7.x installation;
  • drush.

System setup is not covered by this article.

In the following article, let's say:

  • we got a Jenkins server running at http://example.com:8070/jenkins/
  • we got a Drupal website running at http://example.com:80/
  • workspace absolute path is /home/example/example.com/
  • Drupal files are installed in www relative to workspace
  • drush installed and in the shell's PATH
  • Jenkins is configured to store log files in var/jenkins/data relative to workspace

Create Drupal tests: example with the predictable_tests module

The creation of Drupal tests is not covered by this article.

You can follow simpletest module documentation [4].

In this article, we are to use the predictable_tests [5] module.

The predictable_tests module registers tests that always or never pass. We will use them to:

  • make sure that our continuous integration service acts as expected;
  • make sure there is no error in our installation. As examples, errors could be related to Drupal or simpletest;
  • try the continuous integration service with "quick" tests. Standards tests bundled with Drupal or simpletest are quite slow to run. So predictable_tests will save us time.

Run Drupal tests with the command line

Follow the how to run tests with Drupal [1] article to get details about running tests with Drupal and examples used in this article.

When you are sure that you can export tests as XML with drush, let's look at Jenkins...

Configure a Jenkins job

  • Go to Jenkins administration interface at http://example.com:8070/jenkins/

  • Create a new job. Give it a name and choose "free-style" option.

  • Configure the job:

    • For now, we will leave most options blank: let's focus on connecting Jenkins to Drupal. We may improve things later.

    • In the "build" section, click "Add build step" and add a "Execute shell" step with the following code :

      PROJECT_ROOT=/home/example/example.com/
      cd $PROJECT_ROOT
      XML_REPORTS_DIR=$WORKSPACE/$BUILD_ID
      echo $XML_REPORTS_DIR
      mkdir -p $XML_REPORTS_DIR
      bin/drush test-run --uri=http://example.com/ --xml=$XML_REPORTS_DIR PredictableUnitTest
      
    • In "Post-build actions" section, enable "Publish JUnit test result report" and set "Test report XMLs" field to "$BUILD_ID/*.xml".

    • Save.

Run Jenkins job manually

Click the "Build now" link.

In build history, you should see a build progress indicator... When it is done, you can go and see the results. Hope you see "success".

Note

The blue disc means "success". You may enable the "Green balls" plugin to see green markers on success.

Improve Jenkins job

So, we ran some Drupal tests with Jenkins. But we cannot talk about continuous build yet. Here are some steps that we will discuss later:

  • trigger build on some events, such as a cron or a commit on a repository;
  • install, reinstall or upgrade Drupal site during build process;
  • notify build results to development team.

Further readings

References

[1] (1, 2) http://www.makina-corpus.org/blog/metier/archives/running-tests-drupal
[2] http://jenkins-ci.org/
[3] http://pypi.python.org/pypi/jarn.jenkins
[4] http://drupal.org/node/291740
[5] http://drupal.org/sandbox/benoit.bryon/1363566
ABONNEZ-VOUS À LA NEWSLETTER !
Voir aussi
Développer avec Twig dans Drupal 7 Développer avec Twig dans Drupal 7 25/06/2015

Utiliser Twig dans Drupal 7, c'est possible ! Découvrez comment prendre de l'avance sur Drupal 8, ...

Formation Python initiation à Toulouse du 18 au 20 septembre Formation Python initiation à Toulouse du 18 au 20 septembre 06/07/2017

Vous êtes développeur et maîtrisez déjà un langage de programmation ? Python vous tente et ...

Comment mettre en place un site Drupal "Headless" ? Comment mettre en place un site Drupal "Headless" ? 14/06/2017

Les différents modules et techniques pour mettre en place une couche de services web sur une base ...

Initiation au Machine Learning avec Python - La théorie Initiation au Machine Learning avec Python - La théorie 07/06/2017

Dans ce tutoriel en 2 parties nous vous proposons de découvrir les bases de l'apprentissage ...

Initiation au Machine Learning avec Python - La pratique Initiation au Machine Learning avec Python - La pratique 07/06/2017

Dans ce tutoriel en 2 parties nous vous proposons de découvrir les bases de l'apprentissage ...