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
Bien configurer ses tests Python avec tox et Travis Bien configurer ses tests Python avec tox et Travis 18/03/2019

Le plus difficile dans le développement des tests unitaires c'est souvent de se motiver à écrire ...

Découvrez la formation initiation au Python Scientifique Découvrez la formation initiation au Python Scientifique 24/11/2017

La formation initiation au Python scientifique vous permettra de vous initiez à la programmation ...

Mon Top 30 des modules Drupal 8 Mon Top 30 des modules Drupal 8 16/02/2019

Transcription d'une conférence donnée au Drupalcamp Paris 2019

Makina Corpus lance une nouvelle offre pour sécuriser les projets Drupal des ESN Makina Corpus lance une nouvelle offre pour sécuriser les projets Drupal des ESN 18/02/2019

Formations et accompagnement pour sécuriser les projets Drupal

Formation Python à Nantes du 10 au 12 décembre Formation Python à Nantes du 10 au 12 décembre 13/11/2018

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