Skip to content

Latest commit

 

History

History
203 lines (151 loc) · 4.53 KB

File metadata and controls

203 lines (151 loc) · 4.53 KB
type slide
slideOptions
transition width height margin
slide
1400
900
0.1
<style> .reveal strong { font-weight: bold; color: orange; } .reveal p { text-align: left; } .reveal section h1 { color: orange; } .reveal section h2 { color: orange; } .reveal code { font-family: 'Ubuntu Mono'; color: orange; } .reveal section img { background:none; border:none; box-shadow:none; } </style>

GitLab CI/CD


What is "GitLab CI/CD"?

GitLab CI/CD is a tool for software development using the continuous methodologies

From: https://docs.gitlab.com/ee/ci/

  • GitLab's integration automation tool
  • Similar to GitHub Actions though details are different
  • Typically (more than for GitHub Actions): self-hosted runners
    • More effort, more flexibility

Components (1/2)

  • Pipelines: Collection of one or more jobs
  • Jobs: Set of steps of a pipeline (same runner)
    • Jobs in one stage my be executed in parallel
  • Stages: Group jobs and determine running order
  • Runner: Server that runs jobs
  • Artifacts: Files to be shared between jobs or to be kept after workflow finishes
  • No "Actions", but instead integrated features
    • Repository checked out by default
    • Handling of artifacts integrated
    • ...

Components (2/2)

From GitLab CI/CD tutorial


Setting up a Workflow/Pipeline

  • Workflow file stored in ${REPO_ROOT}/.gitlab-ci.yml
  • Configured via YAML file
  • Example for a basic pipeline:
stages:
  - build
  - test
  - deploy

image: alpine

build job:
  stage: build
  script:
    - echo "This job builds something."

test job:
  stage: test
  script:
    - echo "This job tests something. It will only run when all jobs in the build stage are complete."

deploy job:
  stage: deploy
  script:
    - echo "This job deploys something. It will only run when all jobs in the test stage complete."

(Environment) Variables

  • Can be set in different scopes

    variables:
      TEST_VAR: "All jobs can use this variable"
    
    job1:
      variables:
        TEST_VAR_JOB: "Only job1 can use this variable"
      script:
        - echo "$TEST_VAR" and "$TEST_VAR_JOB"
  • There are lots of predefined variables


Artifacts

  • Data sharing between jobs and data upload

  • Uploading artifact

    create file:
      script: echo "Content of my file" > my_file.txt
      artifacts:
        paths:
          - my_file.txt
        expire_in: 5 days
  • Downloading artifact

    read file:
      stage: test
      script: cat my_file.txt
      dependencies:
        - create file

Workflow Triggers

  • By default pipelines are created for every commit

  • Filtering by type of events

  • Example: Run job only for merge requests

    job1:
      rules:
        - if: $CI_PIPELINE_SOURCE == 'merge_request_event'

    or

    job1:
      only:
        - merge_requests

GitLab Runner

  • Supports a variety of executors:
    • SSH, Shell, Docker...
  • Allows reusing existing hardware
  • Preconfigured runners available on gitlab.com

Demo: GitLab Runner

  • Installation of a GitLab Runner on a bwCloud VM (via Docker)
  • Registration of the runner to a repository (Docker as executor)

Advanced Topics


Further reading