GitLab CI
May 7, 2022 — 20:36

Author: silver  Category: dev linux  Comments: Off

There’s a lot of things to like about GitLab in my opinion such as it’s API’s, the MR workflow and Terraform integration to name a few. Of course, there’s things to dislike too ;-)

Below are a few tips and notes on working with CI and editing .gitlab-ci.yml.

For a proper quick start see:



Predefined vars:

  • Package Registry: $CI_REGISTRY (docker login)
  • Docker image: $CI_REGISTRY_IMAGE
  • Build dir: $CI_PROJECT_DIR (docker WORKDIR)
  • Debugging: $CI_DEBUG_TRACE: "true"

Full list:

Conditional var:

Example where if INSTALL_ALL is set to "false", a docker image tag is added:

  INSTALL_ALL = "true"

    - if: $INSTALL_ALL == "false"
        DOCKER_IMAGE: "${CI_REGISTRY_IMAGE}/foo:slim"



Besides using the debug var mentioned above, this kludge is also useful when debugging. To quickly disable a job add a dot in front of it’s name “my_build_job”:

  - test
  - build

 stage: test
 < ... >

  stage: build
  < ... >



This is one line:

  - test -d dir &&
      echo "dir exists"

Multi line:

  - |
    echo "One"
    echo "Two"



First add tag(s) to runner in GitLab GUI: ‘Settings > CI/CD > Runners’. Then use those tags in gitlab-ci.yml to select a specific runner for job execution.

E.g. add inside job:

   - docker
   - socket


Docker in Docker (dind)

Used to build containers. For own self-hosted Runners there’s 2 possible methods using the docker executer: "privileged" or "socket".

This requires changing config.toml, under [runners.docker]:

Add "/var/run/docker.sock:/var/run/docker.sock" to volumes

Or privileged = true

The socket method is more secure but can be a bit more difficult to work with. For example when you need access to $CI_PROJECT_DIR inside container. A solution is available here.

It’s also possible to use the shell executor (also allows using docker compose).

Other alternatives are using Podman/Buildah or Kaniko instead of Docker.

For details see

We use Matomo free and open source web analytics
We also use Jetpack Stats which honors DNT