Skip to content
Latchkey

GitLab CI "extends" Too Deep - Nesting Limit Exceeded

extends supports inheritance up to a fixed nesting depth (11 levels). A chain of templates extending templates that exceeds that limit cannot be resolved and is rejected.

What this error means

Validation fails complaining about the nesting/inheritance level for an extends chain. The individual jobs look fine, but the merge depth is too great for GitLab to flatten.

Pipeline Editor
This GitLab CI configuration is invalid:
jobs:deploy: nesting too deep, max 11 levels of inheritance allowed

Common causes

Deep template chains

Template A extends B extends C … beyond 11 levels. Layered shared CI libraries that each extend the previous one accumulate depth quickly.

extends as a list multiplying depth

A job that extends multiple templates, each of which itself extends others, compounds the effective nesting and can cross the limit.

How to fix it

Flatten the inheritance chain

Collapse intermediate templates so jobs extend a small number of leaf templates directly rather than a deep chain.

.gitlab-ci.yml
# Instead of A -> B -> C -> ... extend a flat set of leaf templates:
.base_image:
  image: node:20
.base_cache:
  cache: { paths: [node_modules/] }

test:
  extends: [.base_image, .base_cache]
  script: npm test

Use !reference for shared fragments

Pull individual keys from templates with !reference instead of inheriting whole chains, avoiding deep extends nesting.

How to prevent it

  • Keep extends hierarchies shallow - jobs extend leaf templates, not chains.
  • Prefer composing a few flat templates via list extends.
  • Use !reference for fine-grained reuse instead of deeper inheritance.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →