GitLab CI

Table of Contents

Overview

image: ruby:2.1
services:
  - postgres

before_script:
  - bundle install

after_script:
  - rm secrets

stages:
  - build
  - test
  - deploy

job1:
  stage: build
  script:
    - execute-script-for-job1
  only:
    - master
  tags:
    - docker

Reference

beforescript

afterscript

stages

stages:
  - build
  - test
  - deploy
  1. First, all jobs of build are executed in parallel.
  2. If all jobs of build succeed, the test jobs are executed in parallel.
  3. If all jobs of test succeed, the deploy jobs are executed in parallel.
  4. If all jobs of deploy succeed, the commit is marked as success.
  5. If any of the previous jobs fails, the commit is marked as failed and no jobs of further stage are executed.

types

variables

variables:
  DATABASE_URL: "postgres://postgres@postgres/my_database"
  LS_CMD: 'ls $FLAGS $$TMP_DIR'
  FLAGS: '-al'
job_name:
  script:
    - echo $CI_JOB_ID     # Defined by CI
    - echo $DATABASE_URL  # Defined in `variables`
    - 'eval $LS_CMD'      # will execute 'ls -al $TMP_DIR'

Note: Integers (as well as strings) are legal both for variable's name and value. Floats are not legal and cannot be used.

cache

By default caching is enabled and shared between pipelines and jobs, starting from GitLab 9.0

cache:
  paths:
  - my/files

rspec:
  script: test
  cache:
    key: rspec
    paths:
    - binaries/  # Locally defined cache overrides globally defined options.

Jobs

job_name:
  script:
    - rake spec
    - coverage
  stage: test
  only:
    - master
  except:
    - develop
  tags:
    - ruby
    - postgres
  allow_failure: true

script

only and except

job:
  # use regexp
  only:
    - /^issue-.*$/
  # use special keyword
  except:
    - branches

Job variables

job_name:
  variables: {}

tags

job:
  tags:
    - ruby
    - postgres

artifacts

artifacts:
  paths:
  - binaries/
  - .config

dependencies

Note that artifacts from all previous stages are passed by default.

build:osx:
  stage: build
  script: make build:osx
  artifacts:
    paths:
    - binaries/

build:linux:
  stage: build
  script: make build:linux
  artifacts:
    paths:
    - binaries/

test:osx:
  stage: test
  script: make test:osx
  dependencies:
  - build:osx  # only downloads artifacts from build:osx

test:linux:
  stage: test
  script: make test:linux
  dependencies:
  - build:linux  # only downloads artifacts from build:linux

# downloads both ~artifacts~ because of the stage precedence
deploy:
  stage: deploy
  script: make deploy

Special YAML features

Anchors

.job_template: &job_definition  # Hidden key that defines an anchor named 'job_definition'
  image: ruby:2.1
  services:
    - postgres
    - redis

test1:
  <<: *job_definition           # Merge the contents of the 'job_definition' alias
  script:
    - test1 project

test2:
  <<: *job_definition           # Merge the contents of the 'job_definition' alias
  script:
    - test2 project

Terminology

Topics

cache vs artifacts,dependencies

How-to

Links