Skip to content

GitLab

GitLab Pipeline Syntax

Variables

variables:
  VARIABLE_NAME: "value"

Stages

stages:
  - build
  - test
  - deploy

Jobs

job_name:
  stage: stage_name
  script:
    - command1
    - command2
  when: manual
  dependencies:
    - job1
    - job2
  environment:
    name: production
    url: https://example.com
  only:
    - master
    - tags
  except:
    - schedules

Steps

step_name:
  script:
    - command1
    - command2
  when: manual
  dependencies:
    - job1
    - job2
  environment:
    name: production
    url: https://example.com
  only:
    - master
    - tags
  except:
    - schedules

Artifacts

artifacts:
  paths:
    - build/
    - binaries/
  expire_in: 1 week
  when: always

Cache

cache:
  key: cache_key
  paths:
    - vendor/
    - node_modules/
  policy: pull-push

Trigger

trigger_name:
  stage: stage_name
  trigger:
    project: group/project
    branch: master

Parallel

parallel:
  matrix:
    - PARAM1: value1
      PARAM2: value2
    - PARAM1: value3
      PARAM2: value4

Services

services:
  - name: postgres
    alias: db
    image: postgres:latest

Dependencies

dependencies:
  - project: group/project
    ref: master
    job: build

Includes

include:
  - project: 'group/project'
    file: 'path/to/another/pipeline.yml'

Resources

resources:
  repositories:
    - repository: 'group/project'
      type: git
      ref: 'master'
      name: 'my-project'

Environments

environment_name:
  url: https://example.com
  on_stop: stop_environment_name
  auto_stop_in: 1 hour
  only:
    - tags
  except:
    - schedules

Deployments

deployment_name:
  environment:
    name: environment_name
    url: https://example.com
  script:
    - command1
    - command2
  when: manual

Reviews

review:
  stage: review
  environment:
    name: review/$CI_COMMIT_REF_NAME
  script:
    - command1
    - command2
  only:
    - branches
  except:
    - master

Pages

pages:
  stage: deploy
  script:
    - command1
    - command2
  artifacts:
    paths:
      - public/
  only:
    - master

Security

sast:
  stage: test
  script:
    - command1
    - command2
  artifacts:
    reports:
      sast: gl-sast-report.json

Secrets

variables:
  DATABASE_PASSWORD:
    vault:
      engine: kv-v2
      path: secret/data/db
      field: password

Deploy Tokens

deploy:
  script:
    - command1
    - command2
  environment:
    url: https://example.com
    name: production
  only:
    - tags
  except:
    - schedules
  variables:
    GIT_STRATEGY: fetch
  when: manual
  needs: []

Dependency Proxy

dependencies:
  proxy:
    image: registry.gitlab.com/gitlab-org/dependency

GitLab Ecosystem

The GitLab ecosystem consists of several building blocks that work together to provide a comprehensive DevOps platform. These building blocks enable teams to manage their source code, automate CI/CD pipelines, track issues and projects, secure their applications, and more. Here are the key components of the GitLab ecosystem:

  • GitLab Repository: At the core of GitLab is the Git repository, where teams store and version control their source code. GitLab provides a web-based interface for managing repositories, including features like branch management, code review, and collaboration.
  • Continuous Integration/Continuous Deployment (CI/CD): GitLab's CI/CD pipelines allow teams to automate the building, testing, and deployment of their applications. GitLab CI/CD provides a configuration file (.gitlab-ci.yml) that defines the stages, jobs, and actions to be executed. It supports parallel testing, deployment to various environments, and integration with other tools.
  • Issue Tracking and Project Management: GitLab provides built-in issue tracking and project management capabilities. Teams can create issues, assign tasks, track progress, and manage project milestones. This integrated approach helps streamline development workflows and facilitates collaboration among team members.
  • GitLab Runners: GitLab Runners are agents that execute jobs defined in CI/CD pipelines. They can be deployed on different operating systems and environments, allowing teams to run tests, build artifacts, and deploy applications to various platforms. GitLab Runners can be self-managed or used with GitLab's shared runners.
  • GitLab Pages: GitLab Pages enables teams to publish static websites directly from their repositories. It simplifies the process of hosting documentation, project websites, or any other static content. GitLab Pages can be configured to automatically update based on repository changes.
  • GitLab Container Registry: GitLab Container Registry provides a built-in Docker container registry for storing and managing container images. It allows teams to push, pull, and share container images within their organization securely. Integration with GitLab CI/CD enables seamless deployment of containerized applications.
  • GitLab Security: GitLab offers a range of security features to help teams identify and address vulnerabilities in their code and infrastructure. This includes built-in static application security testing (SAST), dependency scanning, container scanning, and more. GitLab also integrates with external security tools and provides security dashboards for tracking and managing security vulnerabilities.
  • GitLab Integrations: GitLab integrates with numerous tools and services, enabling teams to connect their workflows seamlessly. It integrates with popular issue trackers, chat tools, monitoring systems, and cloud platforms. This allows teams to leverage their existing toolchain while benefiting from GitLab's centralized platform.