- Examples
- Merge request child pipelines
- Dynamic child pipelines
- Nested child pipelines
- Pass CI/CD variables to a child pipeline
Parent-child pipelines
As pipelines grow more complex, a few related problems start to emerge:
Additionally, sometimes the behavior of a pipeline needs to be more dynamic. The ability
to choose to start sub-pipelines (or not) is a powerful ability, especially if the
YAML is dynamically generated.
Similarly to multi-project pipelines, a pipeline can trigger a
set of concurrently running child pipelines, but within the same project:
Child pipelines work well with other GitLab CI/CD features:
See the
For an overview, see .
The simplest case is triggering a child pipeline using a
local YAML file to define the pipeline configuration. In this case, the parent pipeline
triggers the child pipeline, and continues without waiting:
You can include multiple files when defining a child pipeline. The child pipeline’s
configuration is composed of all configuration files merged together:
In ,
you can use The maximum number of entries that are accepted for Similar to multi-project pipelines,
we can set the parent pipeline to depend on the status of the child pipeline upon completion:
To trigger a child pipeline as a merge request pipeline we need to:
Configure the child pipeline by either:
Setting all jobs in the child pipeline to evaluate in the context of a merge request:
Alternatively, setting the rule per job. For example, to create only
Instead of running a child pipeline from a static YAML file, you can define a job that runs
your own script to generate a YAML file, which is then used to trigger a child pipeline.
This technique can be very powerful in generating pipelines targeting content that changed or to
build a matrix of targets and architectures.
For an overview, see .
We also have an example project using
which shows how to use a data templating language to generate your The artifact path is parsed by GitLab, not the runner, so the path must match the
syntax for the OS running GitLab. If GitLab is running on Linux but using a Windows
runner for testing, the path separator for the trigger job would be In GitLab 12.9, the child pipeline could fail to be created in certain cases, causing the parent pipeline to fail.
This is Dynamic child pipeline example
You can trigger a child pipeline from a dynamically generated configuration file:
The Parent and child pipelines were introduced with a maximum depth of one level of child
pipelines, which was later increased to two. A parent pipeline can trigger many child
pipelines, and these child pipelines can trigger their own child pipelines. It’s not
possible to trigger another level of child pipelines.
For an overview, see .
You can pass CI/CD variables to a downstream pipeline using the same methods as
multi-project pipelines:
include
increase the complexity of the configuration, and create the potential
for namespace collisions where jobs are unintentionally duplicated.
rules: changes
to trigger pipelines only when
certain files change. This is useful for monorepos, for example.
.gitlab-ci.yml
and the child pipeline run as normal
pipelines, they can have their own behaviors and sequencing in relation to triggers.
trigger
keyword documentation for full details on how to
include the child pipeline configuration.
Examples
microservice_a:
trigger:
include: path/to/microservice_a.yml
microservice_a:
trigger:
include:
- local: path/to/microservice_a.yml
- template: Security/SAST.gitlab-ci.yml
include:file
to trigger child pipelines
with a configuration file in a different project:
microservice_a:
trigger:
include:
- project: 'my-group/my-pipeline-library'
ref: 'main'
file: '/path/to/child-pipeline.yml'
trigger:include
is three.
microservice_a:
trigger:
include:
- local: path/to/microservice_a.yml
- template: Security/SAST.gitlab-ci.yml
strategy: depend
Merge request child pipelines
# parent .gitlab-ci.yml
microservice_a:
trigger:
include: path/to/microservice_a.yml
rules:
- if: $CI_MERGE_REQUEST_ID
# child path/to/microservice_a.yml
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID
job1:
script: ...
job2:
script: ...
job1
in
the context of merge request pipelines:
# child path/to/microservice_a.yml
job1:
script: ...
rules:
- if: $CI_MERGE_REQUEST_ID
job2:
script: ...
Dynamic child pipelines
.gitlab-ci.yml
at runtime.
You could use a similar process for other templating languages like
ytt.
/
. Other CI/CD
configuration for jobs, like scripts, that use the Windows runner would use \
.
generate-config:
stage: build
script: generate-ci-config > generated-config.yml
artifacts:
paths:
- generated-config.yml
child-pipeline:
stage: test
trigger:
include:
- artifact: generated-config.yml
job: generate-config
generated-config.yml
is extracted from the artifacts and used as the configuration
for triggering the child pipeline.
Nested child pipelines
Pass CI/CD variables to a child pipeline
Help & feedback
Docs
Edit this page to fix an error or add an improvement in a merge request.Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.Propose functionality by submitting a feature request.
to help shape new features.
Feature availability and product trials
to see all GitLab tiers and features, or to upgrade.with access to all features for 30 days.
Get Help
If you didn't find what you were looking for,
search the docs.
If you want help with something specific and could use community support,
.
For problems setting up or using this feature (depending on your GitLab
subscription).