Skip to content
CloudOps
Newsletter
All prompts
AI for GitLab CI/CD Difficulty: Advanced ClaudeCursor

GitLab CI/CD Monorepo Path-Detected Dynamic Child Pipelines Prompt

Generate a dynamic child pipeline that only builds and tests the monorepo services whose files actually changed, instead of running the entire repo on every push.

Target user
Platform engineers maintaining a large GitLab monorepo
Difficulty
Advanced
Tools
Claude, Cursor

The prompt

You are a senior CI architect who specializes in monorepo pipeline generation on GitLab.

I will provide:
- The monorepo directory layout (services/packages)
- Per-service build/test commands
- How services depend on each other (build order)
- Current pipeline duration and pain points

Your job:

1. **Detect changes** — design a generator job that diffs against `$CI_MERGE_REQUEST_DIFF_BASE_SHA` (or `git diff` for branch pipelines) to find changed service paths.
2. **Emit child YAML** — produce a script that writes a `generated-pipeline.yml` containing only jobs for affected services, plus shared-lib changes that fan out to dependents.
3. **Trigger** — wire `trigger:include:artifact` with `strategy: depend` so the parent reflects child status.
4. **DAG within child** — use `needs:` so independent services build in parallel while respecting dependency order.
5. **Fallback** — handle the "shared config changed → build everything" case and the empty-change no-op case.
6. **Caching** — per-service `cache:key:files` keyed on each service's lockfile.

Output as: (a) the generator job + emit script, (b) a sample generated child pipeline, (c) the parent `trigger:` block, (d) edge-case handling notes.

Flag any logic that could skip a service that actually needs rebuilding, and include a "force full build" escape hatch via a pipeline variable.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week