Skip to content

Support variables in include: section of gitlab-ci.yml

Issues we've implemented to solve this request

Problem to solve

We cannot use variables in the include: section of gitlab-ci.yml (see the documentation for where variables can be used). This encourages repetition, which violates the DRY principle. For example, the Delivery team has a common project that brings in common CI configuration and also has a common image - notice the repeating ref number:

---
include:
  - project: "gitlab-com/gl-infra/k8s-workloads/common"
    ref: 'v1.3.0'
    file: "/ci/except-com.yml"
  - project: "gitlab-com/gl-infra/k8s-workloads/common"
    file: "/ci/cluster-init-before-script.yml"
    ref: 'v1.3.0'
  - project: "gitlab-com/gl-infra/k8s-workloads/common"
    file: "/ci/shellcheck.yml"
    ref: 'v1.3.0'

variables:
  CI_IMAGE_VERSION: 'v1.3.0'

.deploy:
  image: "${CI_REGISTRY}/gitlab-com/gl-infra/k8s-workloads/common/k8-helm-ci:$CI_IMAGE_VERSION"

Proposal

It would be much nicer and less repetitive to refer to a variable:

---
variables:
  CI_IMAGE_VERSION: 'v1.3.0'

include:
  - project: "gitlab-com/gl-infra/k8s-workloads/common"
    ref: "$CI_IMAGE_VERSION"
    file: "/ci/except-com.yml"
  - project: "gitlab-com/gl-infra/k8s-workloads/common"
    file: "/ci/cluster-init-before-script.yml"
    ref: "$CI_IMAGE_VERSION"
  - project: "gitlab-com/gl-infra/k8s-workloads/common"
    file: "/ci/shellcheck.yml"
    ref: "$CI_IMAGE_VERSION"


.deploy:
  image: "${CI_REGISTRY}/gitlab-com/gl-infra/k8s-workloads/common/k8-helm-ci:$CI_IMAGE_VERSION"

Related links

Edited by Dov Hershkovitch