How to Use Dynamic Child Pipelines in GitLab CI
A generator job writes a YAML file and a trigger job runs it, letting one repo emit a pipeline tailored to the diff.
First a job produces a .gitlab-ci.yml artifact, then a downstream trigger job runs it as a child pipeline. This is how monorepos build only changed services.
Generate then trigger
The generate job writes the config as an artifact; the trigger job includes that artifact as a child pipeline.
.gitlab-ci.yml
generate:
stage: build
script:
- ./scripts/generate-pipeline.sh > generated.yml
artifacts:
paths:
- generated.yml
run-children:
stage: test
trigger:
include:
- artifact: generated.yml
job: generate
strategy: dependNotes
- strategy: depend makes the parent wait on and inherit the child pipeline status.
- The generated YAML is a full pipeline definition, so it can declare its own stages, jobs, and rules.
- Use this to fan out per-service jobs in a monorepo without hand-writing every job.
Related guides
How to Run a Parallel Test Matrix in GitLab CIRun tests across multiple versions in GitLab CI with parallel:matrix, and split a single suite into shards wi…
How to Set Up a Merge Request Pipeline in GitLab CIConfigure merge request pipelines in GitLab CI with workflow:rules so jobs run on the MR context, avoiding du…