GitLab Pipelines

Created: 02.02.2025
Updated: 16.04.2025


Look into:

Pipeline are multiple jobs together separated into stages. Each stage has to complete so the next can start. Defined in:

.gitlab-ci.yaml

## Example/Template

workflow:
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

variables:
  APP_VERSION: "1.0.0"

stages:
  - build
  - test
  - deploy

build_job:
  stage: build
  script:
    - echo "Building application version $APP_VERSION"
    - echo "$CI_JOB_STAGE" > build_info.txt
  artifacts:
    paths:
      - build_info.txt
    expire_in: 1 week

test_job:
  stage: test
  script:
    - echo "Running tests"
    - cat build_info.txt
  needs:
    - build_job

deploy_job:
  stage: deploy
  script:
    - echo "Deploying to production"
    - echo $DB_PASSWORD
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
  environment:
    name: production
  needs:
    - test_job

trigger_downstream:
  stage: deploy
  trigger:
    project: group/downstream-project
    branch: main
  rules:
    - if: $CI_COMMIT_BRANCH == "main"

# Credits/See Also