---
title: "An Installer for Drupal 8 and GitLab CI"
url: "/articles/installer-drupal-8-and-gitlab-ci"
type: article
date: 2019-09-11
updated: 2021-01-12
---

# An Installer for Drupal 8 and GitLab CI

#  An Installer for Drupal 8 and GitLab CI 

 Since the Drupal and GitLab partnership landed, we have been askedÂ aboutÂ when we would write an installer for GitLab. This article announcesÂ such integration.

 By

 [  Juampy NR   ](/about/juampy-nr) 

 September 11, 2019

  

Itâ&#128;&#153;s been great to see the activity and excitement around the [repository](https://github.com/Lullabot/drupal9ci) where we host one-line installers to connect Drupal 8 projects with popular continuous integration tools. Since the [Drupal and GitLab partnership](https://about.gitlab.com/blog/drupal-moves-to-gitlab/) landed, we have been asked about when we would write an installer for GitLab. This article announces such integration.

ð&#159;¤&#147; *If you want to dive right into the code, here are the [installer instructions](https://github.com/Lullabot/drupal9ci) and here is the [sample project repository](https://gitlab.com/juampynr/drupal8-gitlab).*

## GitLab: more than CI

I am impressed with what the GitLab folks have built. While CircleCI and Travis CI are continuous integration and delivery tools, GitLab offers a holistic approach to DevOps, with a set of tools to manage the development life cycle.

 ![GitLab tools](/sites/default/files/styles/max_900/public/2019-09/gitlab-tools.png.webp?itok=aWJo7o6L)

## Project setup

Here is the setup required to run the GitLab pipeline in your project:

1. Create a Drupal 8 project via the [composer template command](https://github.com/drupal-composer/drupal-project).
2. Run the Drupal installation.
3. Add `web/sites/default/settings.php` to the repository and uncomment the section that loads a `settings.local.php` file if it exists.
4. Run the [GitLab CI installer](https://github.com/Lullabot/drupal9ci), which will add all the required files to run the pipeline when code changes are pushed to GitLab.
5. Create a database dump. Then follow the instructions in the article, [Achieve Rocketship-Fast Jobs in CircleCI by Preinstalling the Database](https://www.lullabot.com/articles/rocket-ship-fast-jobs-circleci-preinstalling-database), to install the database in a Docker MariaDB image.

## The pipeline in action

A [pipeline](https://docs.gitlab.com/ee/ci/pipelines.html#introduction) is the heart of GitLabâ&#128;&#153;s continuous integration: a file where what it should do and when should it do it is defined. Here is the [resulting pipeline](https://gitlab.com/juampynr/drupal8-gitlab/-/pipelines/78351723) from creating a merge request for the [sample Drupal 8 project](https://gitlab.com/juampynr/drupal8-gitlab) that I used to integrate with GitLab:

 ![GitLab pipeline](/sites/default/files/styles/max_900/public/2019-09/pipeline.png.webp?itok=hTCYAD6P)

We configured the above pipeline, so there is a Build job that prepares the environment and then hands it off to the other jobs that perform the actual test running and evaluating. The graph above shows that all the jobs passed, hence the green marks. Clicking on the *Jobs tab* shows the following screen with the timings of each job plus the code coverage percentage:

 ![Pipeline jobs](/sites/default/files/styles/max_900/public/2019-09/pipeline-jobs.png.webp?itok=4EDdnCFt)

In the next section, you will see the contents of the file that defines the above pipeline.

## The .gitlab-ci.yml file

Pipelines are defined in a file called [.gitlab-ci.yml](https://gitlab.com/juampynr/drupal8-gitlab/blob/master/.gitlab-ci.yml) which is located at the root of the repository and uses [YAML syntax](https://en.wikipedia.org/wiki/YAML) to define the stages, steps, and scripts. Here is the first half of the pipeline that powers the screenshots of the above section, which contains a few definitions and templates:

 ![GitLab CI pipeline part 1](/sites/default/files/styles/max_900/public/2019-09/gitlab-ci-1.png.webp?itok=9eXc4wiU)

And here is the second half, where we defined the jobs of the Test stage. Notice the use of the [extends keyword](https://docs.gitlab.com/ee/ci/yaml/#extends), which is a GitLab CI feature that allows reusing and overriding in YAML files.

 ![GitLab CI pipeline part 2](/sites/default/files/styles/max_900/public/2019-09/gitlab-ci-2.png.webp?itok=jRFLWskw)

The script section of each job is simple as it relies on Robo, a PHP task runner to perform tasks such as running a test suite. The next section explains how these tasks work.

## Robo tasks

In the previous screenshot, you saw that each job calls a [Robo](https://robo.li/) task such as `vendor/bin/robo run:code-sniffer`. Robo is a PHP task runner used by projects such as [Drush](https://www.drush.org).

Using Robo simplifies the gitlab-ci.yml file by turning job scripts into tasks that can be reused in other places such as deployments and local development. Here is an example of the task that checks a Drupal 8 project to ensure it follows Drupal coding standards and best practices:

 ![Robo task](/sites/default/files/styles/max_900/public/2019-09/robo-task.png.webp?itok=OPTNQBVX)

## Where is the database?

The `drupal8:existing_site_tests` job requires the projectâ&#128;&#153;s database to run its tests. Instead of hosting a database dump in the cloud so that CircleCI could download it and install it (like we did in the [CircleCI integration with Drupal 8](https://github.com/Lullabot/drupal9ci/blob/master/dist/circleci/.circleci/RoboFile.php)), we pre-installed the database in a MariaDB Docker image. This made jobs simpler and faster since less setup is required to get the database running for a job.

If you're curious about how to set up the MariaDB Docker image for your projectâ&#128;&#153;s database, you can find the details in the article, [Achieve Rocketship-Fast Jobs in CircleCI by Preinstalling the Database](https://www.lullabot.com/articles/rocket-ship-fast-jobs-circleci-preinstalling-database). We used the scripts for this article and pushed the resulting Docker image to GitLabâ&#128;&#153;s [Container Registry](https://docs.gitlab.com/ee/administration/container_registry.html).

## Running a headless browser in GitLab

To test the whole site, we opted for [Moshe Weitzmanâ&#128;&#153;s Drupal Test Traits](https://gitlab.com/weitzman/drupal-test-traits). These tests assume that there is a Drupal site running and are a great alternative to [Behat](https://behat.org/en/latest/) if your team prefers to write tests in PHP instead of [Gherkin](http://behat.org/en/latest/user_guide/gherkin.html).

We [installed Google Chrome](https://github.com/Lullabot/drupal9ci/blob/master/Dockerfile) in the Docker image that we used to run tests, and then we wrote a Robo task that [starts Chrome in the background](https://gitlab.com/juampynr/drupal8-gitlab/blob/master/.gitlab-ci.yml#L76) so tests could run against the site.

If you prefer to use Selenium WebDriver, refer to the documentation at [Drupal Test Traits](https://gitlab.com/weitzman/drupal-test-traits) and [GitLab](https://docs.gitlab.com/ee/ci/examples/end_to_end_testing_webdriverio/#configuring-gitlab-cicd) to set it up.

## Try it out

Navigate to the [drupal8ci](https://github.com/Lullabot/drupal9ci) project and follow the instructions for installing the files onto your Drupal 8 project and start running GitLab pipelines. Alternatively, copy the files that you need from the [sample project](https://gitlab.com/juampynr/drupal8-gitlab).

For a list of additional jobs for your projectâ&#128;&#153;s pipeline, check out [Jean Valverdeâ&#128;&#153;s Gitlab CI for Drupal 8](https://gitlab.com/mog33/gitlab-ci-drupal).

Thanks to [Nate Lampton](https://www.lullabot.com/about/nate-lampton), [Matthew Tift](https://www.lullabot.com/about/matthew-tift), [Andrew Berry](https://www.lullabot.com/about/andrew-berry), and [Ellie Fanning](https://www.lullabot.com/about/ellie-fanning) for their feedback.

 Published in:

- [  Drupal Development   ](/topics/drupal-development)

 

   You must have JavaScript enabled to use this form.

## Get in touch with us

### Tell us about your project. We'd love to hear from you!

 First Name  

 Last Name  

 Your email address  

 Your organization  

 How you heard about us  

 Tell us more 

     Leave this field blank