Introduction to CI/CD with GitLab

Marius Stanca, Software Engineer
@wmariuss

Slides available at smarius.gitlab.io/ci-cd-presentation
source on GitLab, updated 2019-04-29

Agenda

  • CI/CD methodologies
  • CI/CD Workflow Pipeline
  • Why GitLab CI
  • First step with CI/CD
  • Demo
  • Q&A

CI/CD methodologies

CI/CD is a method to frequently deliver apps to customers by introducing automation into the stages of app development.

The main concepts attributed to CI/CD are:

  • Continuous Integration
  • Continuous Delivery
  • Continuous Deployment

Continuous Integration

Every change submitted to an application - even to development branches - it’s built and tested automatically and continuously, ensuring the introduced changes pass all tests, guidelines, and code compliance standards you established for your app.

A CI pipeline typically involves the following tasks:

  • Detect changes in the source code repository (new commits appear)
  • Source code quality analysis
  • Execute all unit tests
  • Execute all integration tests
  • Generate deployable artifacts
  • Report status

Continuous Delivery

Continuous Delivery (CD) is actually an extension of CI, in which the software delivery process is automated further to enable easy and confident deployments into production at any time.

Continuous Deployment

Continuous Delivery (CD) is also an extension of CI, similar to Continuous Delivery. The difference is that instead of deploying your application manually, you set it to be deployed automatically. It does not require human intervention at all to have your application deployed.

CI/CD Workflow Pipeline

Why GitLab CI

  • Visual Reviews
  • Built-in CI/CD
  • Minimal CI/CD configuration
  • Support for Kubernestes: multiple clusters, easy deployment of apps, Cloud Native
  • Protected Runners
  • Group-level variables
  • Environments and deployments
  • Protected variables
  • Built for using containers and Docker
  • CI/CD Horizontal Autoscaling
  • Preview your changes with Review Apps
  • Built-in Container Registry
  • Container debugging with an integrated web terminal
  • Much more

First step with CI/CD

  1. Create or use existing repository
  2. Add new file called ".gitlab-ci.yml"
    • Use docker image: "image:centos:8"
    • Define simple job called "test", executing a "script"
    • Commit and verify CI job
  3. Change the job to success, commit and verify again

Example config file


image: centos:8

test:
  script:
    - echo "Hello!" && exit 1;
					

Demo

  • Use an existing project
  • Add ".gitlab-ci.yml" file in our root project
    • Define basic pipeline for our project
      • Four jobs: check dependencies, tests, deploy to staging and production
    • Commit and verify CI jobs
  • Change the code to fail, commit and verify again

Questions?