gitlab-ci templates

Steps:

TARGET DECK: DevOps/gitlab-ci

basic gitlab-ci template #flashcard

  1. Hide your job putting a dot in front of its name. Example:
.deploy_template:
  stage: deploy
  script:
    - # something...
  1. Extend the template in your actual job:
deploy_prod:
  extends: .deploy_template

An example to deploy in different environments:

###########
# template
###########
.deploy_template
  stage: deploy
  script:
    - # commands
    - deploy $TARGET_SERVER
  variables:
    TARGET_SERVER: ''


###########
# prod
###########
deploy_prod:
  extends: .deploy_template
  variables:
    TARGET_SERVER: example.com
  rules:
    - if: $CI_COMMIT_BRANCH == "master"


###########
# release
###########
deploy_release:
  extends: .deploy_template
  variables:
    TARGET_SERVER: release.example.com
  rules:
    - if: $CI_COMMIT_BRANCH =~ /^release.*/

###########
# dev
###########
deploy_release:
  extends: .deploy_template
  variables:
    TARGET_SERVER: dev.example.com
  rules:
    - if: $CI_COMMIT_BRANCH == "develop"