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.
This GitLab CI configuration is invalid:
jobs:deploy: nesting too deep, max 11 levels of inheritance allowedCommon 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.
# 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 testUse !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
extendshierarchies shallow - jobs extend leaf templates, not chains. - Prefer composing a few flat templates via list
extends. - Use
!referencefor fine-grained reuse instead of deeper inheritance.