Gitlab parent-child pipelines

Mahdieh Asiyaban
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:

  1. Reduces the cognitive load to understand the overall configuration.
  2. Each pipeline has only relevant steps, making it easier to understand what’s going on.
  3. 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-modules
trigger 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/*
  1. 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.
  2. include: path/to/module.yml
  3. 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-maven
build-package maven 1/2:
stage: build-package-maven
script:
- mvn compile
only:
- master
build-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.

--

--

Mahdieh Asiyaban
Mahdieh Asiyaban

No responses yet