Include reference from another file


I’m trying to split my gitlab-ci.yml in multiple files because it’s very big.

I have a file called .cache-ci.yml which looks like this:

cache: &cache
      - package.json
    - .npm
    - cache/Cypress
    - node_modules

I would like to include this file in another file .lint-ci.yml so I have done something like this:

include: '.cache-ci.yml'

# Linting checks
  stage: lint
  image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/timbru31/node-alpine-git:latest
    <<: *cache
    policy: pull
    - git fetch
    - npm run affected:lint
    - npm run stylelint:apps
    - npm run stylelint:libs
    - master
    - /^release-.*$/
    - develop

Finally this file .lint-ci.yml is included in my .gitlab-ci.yml. Unfortunately I get an syntax error:

Included file `ci/.lint-ci.yml` does not have valid YAML syntax!

What am I doing wrong ? My guess is that it is due the reference <<: *cache. I’m doing this because I need to use that cache reference in a lot of places and I don’t want to copy/paste everywhere.

1 Like

I have the same issue.
I guess the & reference is resolved at yaml loading (it’s YAML standard), then GitLab takes include and loads them.
Then the yaml loader can not resolve *cache because &cache is not defined in this file.

Now I’m looking at !reference (Optimize GitLab CI/CD configuration files | GitLab)