Skip to content

GitLab CI ​

GitLab CI is the pipeline engine built into GitLab. It reads .gitlab-ci.yml on every push and hands out the jobs to the runners.

The root file ​

GitLab only reads the file at the root. It includes those from api/ and web/:

yaml
stages:
  - lint
  - test
  - build
  - deploy

workflow:
  rules:
    - if: $CI_COMMIT_BRANCH

include:
  - local: api/.gitlab-ci.yml
  - local: web/.gitlab-ci.yml
  - local: docs/.gitlab-ci.yml

deploy-dev:
  stage: deploy
  tags:
    - dev
  environment:
    name: dev
    url: https://dev.trinity.jostud.com
  script:
    - docker compose -p trinity -f infra/docker-compose.dev.yml up -d --build
    - curl -fsS --retry 20 --retry-delay 3 --retry-all-errors https://api.dev.trinity.jostud.com/health
    - curl -fsS --retry 20 --retry-delay 3 --retry-all-errors https://dev.trinity.jostud.com/api/health
  rules:
    - if: $CI_COMMIT_BRANCH == "develop"

deploy-prod:
  stage: deploy
  tags:
    - prod
  environment:
    name: prod
    url: https://trinity.jostud.com
  before_script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
  script:
    - docker stack deploy --detach=false --with-registry-auth -c infra/docker-compose.prod.yml trinity
    - test "$(docker service ls --format '{{.Image}}' | grep -c "$CI_COMMIT_SHORT_SHA")" = 3
    - curl -fsS https://api.trinity.jostud.com/health
    - curl -fsS https://trinity.jostud.com/api/health
    - curl -fsS -o /dev/null https://docs.trinity.jostud.com/
  after_script:
    - docker logout "$CI_REGISTRY"
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
BlockRole
stagesStep order: lint → test → build → deploy
workflow.rulesA pipeline only for pushes to a branch (no duplicate for merge requests, nothing for tags)
includeAdds the api:* and web:* jobs
deploy-dev, deploy-prodThe deployments, explained in The pipeline

Keywords used ​

KeywordWhat it doesExample in the project
stagePuts the job in a stepstage: test
imageDocker image the job runs inimage: node:22-alpine
scriptThe job's commandsnpm run lint
before_script / after_scriptBefore / after scriptdocker login / docker logout
rules: - changesRuns the job only if these files changedweb/**/*
rules: - ifRuns the job under a condition$CI_COMMIT_BRANCH == "main"
tagsPicks the runnertags: [prod]
servicesA side container during the jobdocker:27.5.1-dind
artifacts: reportsFiles read by GitLabjunit: web/junit.xml
coverageExpression extracting the coverage % from the logs/Lines\s*:\s*(\d+…)%/
cacheKeeps files from one pipeline to the nextthe npm cache, keyed by package-lock.json
environmentLinks the job to a GitLab environment, with its URLname: prod
extendsInherits from a job template.web

Variables provided by GitLab ​

VariableExampleUsed to
CI_COMMIT_BRANCHmainchoose the jobs
CI_COMMIT_SHORT_SHA5a86221tag the images
CI_REGISTRYregistry.gitlab.comlog into the registry
CI_REGISTRY_IMAGEregistry.gitlab.com/epitech_gitlab/trinity-devopsname the images
CI_REGISTRY_USER, CI_REGISTRY_PASSWORDtemporary tokenlog in, valid for the job's duration

The project's secret variables (POSTGRES_PASSWORD, DJANGO_SECRET_KEY) are described in Secrets and access.

Where to see the results ​

In GitLabWhat you see
Build → PipelinesEach pipeline, its stages and jobs, with the logs
A pipeline's Tests tabThe API and web JUnit reports
A merge requestPipeline status, tests, coverage in the diff
Operate → EnvironmentsThe version deployed in dev and prod, and the button to redeploy an older version
Deploy → Container RegistryThe api and web images and their tags

rules: changes on a push

For a push to a branch, GitLab compares against the previous push. On the first push of a new branch, there is nothing to compare: every job with changes runs.