GitLab CI/CD Dynamic Child Pipeline Generation Prompt
Generate `.gitlab-ci.yml` at runtime — emit child-pipeline YAML from a script based on changed paths, a matrix file, or service inventory, then trigger it with artifact-based config.
- Target user
- Platform engineers building data-driven pipelines for monorepos and large service catalogs
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior CI/CD engineer who builds dynamic child pipelines that generate themselves from the repo state, so adding a new service requires zero `.gitlab-ci.yml` edits.
I will provide:
- My repo layout (services/packages, languages, where build configs live)
- The decision logic I want (per-service jobs only for changed paths? full matrix on main? tags?)
- My GitLab tier and runner setup
- Any existing static `.gitlab-ci.yml`
Your job:
1. **Choose the trigger pattern** — a `generate` job that writes `generated-config.yml` as an artifact, then a `trigger` job with `trigger: include: [{ artifact: generated-config.yml, job: generate }]` and `strategy: depend`. Explain `strategy: depend` (parent waits + inherits status) vs fire-and-forget.
2. **Write the generator** — a small, readable script (Python or bash+yq) that: detects changed paths via `git diff` against `CI_MERGE_REQUEST_DIFF_BASE_SHA` (MRs) or the previous SHA (branches), maps each to a job template, and emits valid YAML. Provide the actual generator code.
3. **Keep generated YAML DRY** — emit `extends:` references to a hidden `.job_template` and pass per-service values via `variables:`, instead of duplicating full job bodies.
4. **Handle the empty case** — when nothing relevant changed, emit a single no-op `pipeline: cannot be empty` guard job (GitLab rejects empty child configs); show the pattern.
5. **Propagate context** — which variables auto-pass to children, which need explicit `variables:` forwarding, and how `CI_PIPELINE_SOURCE` differs inside a child.
6. **Make it debuggable** — echo the generated YAML to the job log, upload it as a browsable artifact, and run `gitlab-ci-lint` (or the `/ci/lint` API) on it before triggering so a malformed generation fails fast with a clear message.
7. **Failure semantics** — with `strategy: depend`, how a failing child surfaces in the parent; `allow_failure` behavior; and how to retry only the child.
Output: (a) parent `.gitlab-ci.yml` with generate + trigger jobs, (b) the generator script, (c) a generated-config example for a 2-service change, (d) the lint/validation step, (e) common failure modes and fixes.
Bias toward: validated-before-trigger, readable generated YAML, and zero edits to add a new service.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
GitLab Monorepo CI/CD Prompt: Selective Builds & Child Pipelines
Design GitLab CI/CD for monorepos — selective builds via rules:changes, per-service child pipelines, shared-library detection and dependency-aware fan-out.
-
GitLab CI/CD Sparse-Checkout Monorepo Performance Prompt
Speed up GitLab CI clones in large monorepos with sparse-checkout, shallow depth, and partial clone — fetch only the paths a job needs without breaking builds.
-
GitLab CI/CD k6 Load Test Performance Gate Prompt
Design a .gitlab-ci.yml stage that runs k6 load/performance tests against a review or staging environment, enforces threshold-based pass/fail gates, and surfaces results as artifacts and metrics reports in merge requests.
-
GitLab CI/CD Publish to the Package Registry (npm, Maven, generic) Prompt
Design .gitlab-ci.yml jobs that build and publish versioned artifacts to the project or group Package Registry using CI_JOB_TOKEN auth, with proper version gating, immutability, and consumer install config.
More GitLab CI/CD prompts & error guides
Browse every GitLab CI/CD prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.