Search code examples
continuous-integrationgitlabincludegitlab-ci

Avoid path redundancy in Gitlab CI include


To improve the structure of my Gitlab CI file I include some specific files, like for example

include:
  - '/ci/config/linux.yml'
  - '/ci/config/windows.yml'
  # ... more includes

To avoid the error-prone redundancy of the path I thought to put it into a variable, like:

variables:
  CI_CONFIG_DIR: '/ci/config'

include:
  - '${CI_CONFIG_DIR}/linux.yml'    # ERROR: "Local file `${CI_CONFIG_DIR}/linux.yml` does not exist!"
  - '${CI_CONFIG_DIR}/windows.yml'
  # ... more includes

But this does not work. Gitlab CI claims that ${CI_CONFIG_DIR}/linux.yml does not exist, although the documentation says that variables in include paths are allowed, see https://docs.gitlab.com/ee/ci/variables/where_variables_can_be_used.html#gitlab-ciyml-file.

What also didn't work was to include a file /ci/config/main.yml and from that include the specific configurations without paths:

# /ci/config/main.yml
include:
  - 'linux.yml'    # ERROR: "Local file `linux.yml` does not exist!"
  - 'windows.yml'
  # ... more includes

How can I make this work or is there an alternative to define the path in only one place without making it too complicated?


Solution

  • This does not seem to be implemented at the moment, and there is an open issue at the moment in the backlog.

    Also, with the documentation saying that you could use variables within include sections, those are only for predefined variables.