Gitlab-ci.yml linting fails when using extends and include

I’m trying to use “include” in my gitlab-ci.yml to pull in an external file with shared code. In a job, I want to use “extends” to consume the template defined in the file pulled in with include. However, when I push this, the linter fails, indicating that the key defined in the “extends” section is not found. If I pull the content from the external file into the main gitlab-ci.yml file, it passes linting fine.

The docs indicate that included files are merged in before the other steps are done, so I’m not sure why this isn’t working.

Here is the gitlab-ci.yml file:

image: docker

include:
  - 'https://myrepo.com/build.yaml'

stages:
  - build
  - test
  - deploy

buildit:
  extends: .build_template
  stage: build

Here is the build.yaml file:

.build_template:
  services:
    - docker:dind
  script:
    - echo "This is in the shared code."

And here is the error:

**Status:** syntax is incorrect

**Error:** buildit: unknown key in `extends`
1 Like

I think you’d need to include the “.build_template” not build.yaml, because you want to include the task not the file. But i am also very new to gitlab so be gentle if I’m talking rubbish.

If it’s in the same project just do this:

include: .build_template.yml

Or if myrepo.com is a different project name:

include:

  • project: ‘myrepo.com
    file: ‘/.build_template.yaml’