Drupal and Jenkins: continuous integration howto
Prerequisites: system setup
- a Jenkins server. Python users may use the jarn.jenkins  recipe for buildout;
- a Drupal 7.x installation;
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.
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
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".
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".
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.
|||(1, 2) http://www.makina-corpus.org/blog/metier/archives/running-tests-drupal|