GitLab Monorepo CI/CD Pipeline Guide
Learn how to design GitLab CI/CD pipelines for monorepos using folder-based rules, changed-file detection, child pipelines, shared templates, cache, artifacts, and deployment controls.
Quick answer
Use path rules
Run frontend jobs only when frontend files change, backend jobs only when backend files change.
Use shared templates
Keep common logic in reusable includes to avoid repeating YAML.
Use child pipelines
For large monorepos, split pipelines by app or service.
Sample monorepo structure
monorepo/ apps/ frontend/ api/ services/ worker/ infra/ terraform/ .gitlab-ci.yml
Run jobs only when paths change
frontend_tests: stage: test script: - cd apps/frontend - npm ci - npm test rules: - changes: - apps/frontend/**/* api_tests: stage: test script: - cd apps/api - pip install -r requirements.txt - pytest rules: - changes: - apps/api/**/*
Use workflow rules
Workflow rules help control whether a pipeline should be created at all.
workflow: rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - if: '$CI_COMMIT_BRANCH == "main"' - when: never
Use child pipelines for larger monorepos
When a monorepo grows, a single giant YAML file becomes hard to maintain. Child pipelines help split responsibilities by folder or service.
frontend_pipeline: trigger: include: apps/frontend/.gitlab-ci.yml rules: - changes: - apps/frontend/**/*
Cache and artifacts in monorepos
| Area | Best practice |
|---|---|
| Frontend cache | Use package-lock based cache keys. |
| Backend cache | Use dependency-file based cache keys. |
| Build output | Use artifacts per app/service. |
| Shared libraries | Run dependent jobs when shared folders change. |
Deployment strategy
- Deploy only the affected app or service.
- Use environment names like frontend/staging and api/production .
- Use manual production deployments.
- Use protected variables for production credentials.
Common mistakes
- Running every job for every small change.
- Using one cache key for the entire monorepo.
- Ignoring shared library dependencies.
- Keeping all YAML in one huge file.
- Deploying all services when only one changed.
Best practices
- Use rules:changes for folder-aware pipelines.
- Use child pipelines for large repositories.
- Use clear app/service ownership.
- Document folder-level pipeline behavior.
- Keep shared templates versioned and reviewed.
- GitLab CI/CD Learning Path
- GitLab Rules and Workflow
- Python, Angular and Django Pipeline Examples
Official references
- GitLab rules:changes documentation
- GitLab downstream and child pipelines
Join the discussion
0 CommentsAsk questions, add context, or share what worked.
More from Melochip Editorial
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
7 min read · Sep 19, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Sep 17, 2026
Learn Kubernetes security best practices with RBAC, Secrets, ServiceAccounts, Pod securityContext, NetworkPoli...
6 min read · Sep 17, 2026Related articles
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
7 min read · Sep 19, 2026
Troubleshoot Kubernetes issues including Pending Pods, CrashLoopBackOff, ImagePullBackOff, service routing, in...
7 min read · Sep 17, 2026
Learn Linux from the ground up with simple explanations of the kernel, distributions, filesystem, commands, pe...
4 min read · Updated Oct 1, 2026
Learn Docker registries, image tags, Docker Hub, private registries, login, push, pull, naming rules, CI/CD us...
2 min read · Sep 17, 2026Stay in the loop. Get new Melochip articles
Receive Melochip article updates when new articles are available. Explicit opt-in only.
No comments yet. Start the discussion.