Include reference from another file

Hi,

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
  key:
    files:
      - package.json
  paths:
    - .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
lint:
  stage: lint
  image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/timbru31/node-alpine-git:latest
  cache:
    <<: *cache
    policy: pull
  before_script:
    - git fetch
  script:
    - npm run affected:lint
    - npm run stylelint:apps
    - npm run stylelint:libs
  except:
    - 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)