Gitlab parent-child pipelines
2 min readAug 25, 2020
If you have a multi-module project and want to implement Gitlab CI/CD for it, you can use Gitlab parent-child pipelines.
Having a parent and several child pipelines will help you to:
- Reduces the cognitive load to understand the overall configuration.
- Each pipeline has only relevant steps, making it easier to understand what’s going on.
- Each pipeline has only relevant steps, making it easier to understand what’s going on.
How to simplify life by using the parent-child pipelines?
Step 1. Create a .gitlab-ci.yml file on the root of the project:
#parent gitlab-cistages:
- trigger-modulestrigger module 1/2:
stage: trigger-modules
trigger:
include: module-one/gitlab-module-one.yml
only:
changes:
- module-one/*trigger module 2/2:
stage: trigger-modules
trigger:
include: module-two/gitlab-module-two.yml
only:
changes:
- module-two/*
- trigger module 1/2: we can group the steps (trigger-modules) for better readability. For example, when we say (trigger module 1/2), which means there are 2 steps and 1 is the first step.
- include: path/to/module.yml
- only: changes: this pipeline will trigger when the module changes.
Step 2. Create a child YAML file with the desired name, for example, gitlab-ci-module-one at the root of each module:
#child gitlab-ciimage: maven:lateststages:
- build-package-mavenbuild-package maven 1/2:
stage: build-package-maven
script:
- mvn compile
only:
- masterbuild-package maven 2/2:
stage: build-package-maven
script:
- mvn clean package
only:
- master
Finally, you can implement your own pipelines based on the logic of your project.
The example for this article can be found on the GitHub repository.