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
Présentation de django-admin-watchdog Présentation de django-admin-watchdog 12/11/2020

Comment garder une trace des erreurs Django en toute simplicité.

Présentation de django-tracking-fields Présentation de django-tracking-fields 03/11/2020

Suivi de modification d'objets Django

Présentation de Django-Safedelete Présentation de Django-Safedelete 09/07/2013

Masquage d'objets en base de données une alternative à la suppression définitive.

Migrer une application de Python 2 à Python 3 Migrer une application de Python 2 à Python 3 21/07/2020

Le support de Python 2 est officiellement terminé, c'est le moment de passer vos applications à ...

Wagtail : Comment écrire les templates (partie 3) Wagtail : Comment écrire les templates (partie 3) 18/07/2016

Il n'y a pas de vue à proprement parlé dans Wagtail. Tout est en fait géré dans le modèle. ...