GitLab CI/CD

ENV variables
https://docs.gitlab.com/ee/ci/variables/predefined_variables.html

Build and push Docker Images with Gitlab CI

# .gitlab-ci.yml
build:
  stage: build
  image: docker:19.03.1
  services:
    - docker:dind
  before_script:
    - echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
  script:
    - docker build --pull -t "$CI_REGISTRY_IMAGE" .
    - docker push "$CI_REGISTRY_IMAGE"
  tags:
    - docker
 
# Dockerfile
FROM alpine:3.10
 
RUN apk add --no-cache nginx

Reuse commands across Gitlab jobs
https://jsramblings.com/three-ways-to-reuse-commands-across-gitlab-jobs/

.prepare_step:
  before_script:
    - echo 'prepare'
 
build:
  extends:
    - .prepare_step
  script:
    - echo 'build'
 
test:
  extends:
    - .prepare_step
  script:
    - echo 'test'

Links
https://about.gitlab.com/2016/05/23/gitlab-container-registry/