Skip to main content
Ungathered Thoughts

Gitlab CI

I'm such a fan of firecow/gitlab-ci-local. It's a CLI tool which allows to execute Gitlab CI pipelines locally, without needing to push changes through Gitlab. For fast local development of pipelines, or targeted testing of jobs configured in pipelines, it's an amazing speed boost.

For example, in a local project I might have a job cypress, which perhaps depends on some prior build and install tasks. With gitlab-ci-local installed, from a CLI within the project directory I can execute -

gitlab-ci-local --needs cypress

to see the CI job and its dependencies run locally, in either docker or shell runners.

The tool tracks any files which are tracked by Git. You don't need to commit changes; it's sufficient that the files are tracked, and gitlab-ci-local will use the local versions of the files.

Artifacts from the CI jobs are preserved in /.gitlab-ci-local/artifacts by default, along with a handful of other useful directories which track output

If the job needs some additional CI variables set, I can pass --variable PATH=/some/path or add a /.gitlab-ci-local-variables.yml:

---
# CI_PIPELINE_SOURCE: merge_request_event
XDEBUG_CONFIG: client_host=192.168.178.56

gitlab-ci-local functions as a containerised testing environment with configuration syntax inherited from Gitlab CI. Since I'm already using that for most projects, adding gitlab-ci-local to the mix is fantastic - fast, no-push execution of targeted CI jobs, which I can push to Gitlab once I'm happy with the local tests.

Disk usage!

One thing to watch for with this tool is disk consumption via Docker volumes. When cleaning disk usage on my laptop, including deleting ~800 Docker volumes, 200 of which had names like gcl-{jobname}-{NNN}-(build|tmp) (eg gcl-cypress-126182-build, gcl-cypress-126182-tmp). Just normal Docker things really, but gitlab-ci-local was a bit of a multiplying factor ...

Save steps!

Useful detail to know: if you are changing the job "cypress", and it depends on the job "composer build"

You can run the job gitlab-ci-local --needs cypress first, to execute the build job

Then you can make changes to your code, and run just gitlab-ci-local cypress to skip the build job; if you're not changing composer.lock then the build job is skippable, and this lets you run pipelines again even faster than CI would.

drupal-ci-local

Documentation here for Drupal Gitlab Templates.

If you need extras:

drupal-ci-local --variable _GITLAB_TEMPLATES_REF=default-ref phpunit