...

Dynamic Pipeline Generation on GitLab

Andras Kelle
5 October 2021
Read: 3 min

Running a pipeline in a monorepo can be very resource- and time-consuming.

In version control systems, a monorepo (monolith != monorepo) is a software development strategy where we use the same repository to store code for more than one project. Google, Facebook, Microsoft and other big tech companies all employ monorepos. At first sight you might think that this setup has many disadvantages, such as a large number of commits, branches and tracked files or a lack of access control. However, it also has numerous advantages too, including:

  • visibility
  • easier package management
  • consistency

As projects get more complex, the length of the .gitlab-ci.yml increases in proportion to the content of their repository. Besides the conceptual challenges, numerous performance issues can affect a monorepo setup. Don’t let the pipeline be one of them.

Inside of a pipe

 

Structure and architecture

Automation makes our life easier so let’s use it to generate a configuration file and its content for a child pipeline. At an abstract level, a child pipeline is an automated manifestation of generated processes that execute jobs in a direct acyclic way.

A common practice is to use a for loop to retrieve data over iteration, and save results in an array. In the following example, the concept of the dynamic pipeline generation relies on that after an iteration, elements of an array can be used to create the jobs defined in the generated pipeline.

N.B. I use Python in the examples to replace variables with values during the child-pipeline generation process but feel free to use any other preferred programming language.

Let’s have a look at the directory structure:

 

[php]libs

└── java

└── auth

└── payments

└── subscription

[/php]

 

Since it is an explanatory project, it will not require lots of data; we will only need it to demonstrate the concept.

First, separate the generation and the trigger processes into two different jobs as shown in the .gitlab-ci.yml below. The trigger job should use strategy: depend on the generator because the child-pipeline-trigger will need the generated configuration file, which will be available only after the generation process succeeded and is saved as an artifact.

 

But what’s happening under the hood?

A brief description: The generator job at the child-pipeline-generator stage calls main.py in its script block. That executes the generator() method, which will collect data from get_libs() and create the child pipeline’s configurations file, the child-pipeline-gitlab-ci.yml.

get_libs() iterates through the content of lib/java and returns a list made up of the entities contained by libs_path.

 

The PipelineWriter class contains all the configurations and templates that we need to generate the child pipeline, including hidden (parent) jobs and the child pipeline job template.

As you can see in the example, Gitlab supports extends with multi-level inheritance. The build-{lib}-lib job inherits all the configurations defined in the .basic job.

You can think of these indented multi-line strings returned by each method as different parts of the child pipeline, which can later be put together into a valid configuration file.

 

Tip: Validate your generated configuration file with CI Lint before deploying it.

 

What it looks like on the UI

Dynamically generated jobs
Dynamically generated jobs

Conclusion

In this article, I showed an example of how automation makes our life easier and increases efficiency by relying on GitLab’s child-pipeline processes. I used Python to dynamically generate a configuration file for the child pipeline and, in my opinion, this is a great way to create a more organised YAML file with less repetition.

If you dig into optimisation, you can check beforehand which services/libs, packages or directories have changed (between two build processes) and generate a pipeline determined by them to reduce build time and resource usage.

Additional Resources:

  1. Monorepos in Git | Atlassian Git Tutorial
  2. Parent-child pipelines | GitLab
  3. Keyword reference for the `.gitlab-ci.yml` file | GitLab

 

Head to the Infinite Lambda blog to find other insightful materials.

More on the topic

Everything we know, we are happy to share. Head to the blog to see how we leverage the tech.

10 Questions to Ask Before You Migrate off Legacy ETL
10 questions before legacy etl migration
10 Questions to Ask Before You Migrate off Legacy ETL
I spent about ten years on the buyer side at Johnson & Johnson and AstraZeneca, so I have sat through my share of migration pitches....
12 November 2026
What are Claude Dashboards and is this the death of BI?
Claude Dashboards
What are Claude Dashboards and is this the death of BI?
Anthropic released a new artefact referred to as Claude Dashboards, alongside a short introductory video that showcases how the feature works and how teams can...
15 October 2026
How to plan a predictable ETL migration
plan a predictable ETL migration
How to plan a predictable ETL migration
In the world of data migrations, boring is good. A well-planned project tends to be wonderfully uneventful, making for a predictable ETL migration from start...
9 October 2026
Patterns vs Platforms: What Google Cloud Platform Projects Teach Us about Trust and Speed
Patterns vs Platforms - What Google Cloud Platform Projects Teach Us about Trust and Speed
Patterns vs Platforms: What Google Cloud Platform Projects Teach Us about Trust and Speed
Every client engagement starts the same way: we learn as much as we can about the client so we can support them in reaching their...
2 September 2026
Infinite Lambda Wins Snowflake Partner of the Year Award for ASEAN 2026
Infinite Lambda Wins Snowflake ASEAN Partner of the Year Award 2026
Infinite Lambda Wins Snowflake Partner of the Year Award for ASEAN 2026
Infinite Lambda has won the 2026 Snowflake Partner of the Year award for ASEAN. It is Snowflake's top regional award, given to the partner that...
27 August 2026
Infinite Lambda Achieves ISO 27001 Certification
ISO 27001 certified
Infinite Lambda Achieves ISO 27001 Certification
Infinite Lambda has achieved ISO 27001 certification, the leading international standard for information security management. The certification was awarded by LRQA following an independent audit...
17 July 2026

Everything we know, we are happy to share. Head to the blog to see how we leverage the tech.