---
title: "Discussion on \"How to set up monorepo build in GitLab CI\" | Hashnode"
description: "Discussion on \"How to set up monorepo build in GitLab CI\". If you migrate your multirepo to a monorepo, or if your project is getting big enough to consider running only part of continuous integration (CI) - then it can make sense to run only those parts of CI that could have been affected by the change. Thi..."
url: "https://hashnode.com/posts/how-to-set-up-monorepo-build-in-gitlab-ci/60fd1d7318fbbb77c94672d6"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to set up monorepo build in GitLab CI](https://how-to.dev/how-to-set-up-monorepo-build-in-gitlab-ci?utm_source=hashnode&utm_medium=feed)

If you migrate your multirepo to a monorepo, or if your project is getting big enough to consider running only part of continuous integration (CI) - then it can make sense to run only those parts of CI that could have been affected by the change. Thi...

Jul 25, 2021 · 5 min read · how-to.dev  
Updated Jan 24, 2025  
Read the article

-   [#gitlab](https://hashnode.com/tag/gitlab)

## Written by

[Marcin Wosinek](https://hashnode.com/@marcin-wosinek)

@marcin-wosinek · Valencia, Spain

  
[View profile](https://hashnode.com/@marcin-wosinek)

JavaScript developer

I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.

## Responses 4

Markdown supported · ⌘↵ to post

[Honsemiro](https://hashnode.com/@Honsemiro)

[Feb 21, 2024](https://hashnode.com/posts/how-to-set-up-monorepo-build-in-gitlab-ci/60fd1d7318fbbb77c94672d6/comment/65d5599ad6f5364332bcd29a)

지금 당장 필요한 설명이었습니다!

[David Cardona](https://hashnode.com/@davidpccode)

[Dec 12, 2022](https://hashnode.com/posts/how-to-set-up-monorepo-build-in-gitlab-ci/60fd1d7318fbbb77c94672d6/comment/6397b64632e52b31f1387bac)

Hi. Tks for this article. I always have a big question about this Workflow.

What happen if I merge into main a super feture which work and run perfectly on PR/MR but when run on main there was a small error in a yml file or some missconfiguring file? The code was already merged but no one of the changes was deployed. So I fix the yml but non of the paths defined in change/rules where touched then nothing will de deployed… We cann’t just re run the last failed pipeline because it always checked out agains the old commit..

There is no way to run the same projects that failed unless I touch some files (with empty spaces or enter or whatever change). This is ugly for me.

One idea came up, what if I always build all projects on main but when deploy the docker images that hasn’t changed won’t be deployed

Any ideas? Thanks

[Marcin Wosinek](https://hashnode.com/@marcin-wosinek)

[Dec 13, 2022](https://hashnode.com/posts/how-to-set-up-monorepo-build-in-gitlab-ci/60fd1d7318fbbb77c94672d6/comment/6397b64632e52b31f1387bac#reply-63984df69c2b1a31cc3994cc)

Hey!

Yes, this sounds like a problem that could be very annoying. I think, I managed to avoid this kind of situation with:

1.  [CI](https://how-to.dev/continuous-integration-ci-and-how-it-can-help-you) that will definitively fail if anything is as wrong as broken YML files,
2.  [Rebasing](https://how-to.dev/rebases-in-git-and-why-you-shouldnt-be-afraid-of-them) feature branches all the time

> There is no way to run the same projects that failed unless I touch some files (with empty spaces or enter or whatever change). This is ugly for me.

Triggering jobs manually should do the trick. It's annoying, as you have to trigger them in the right order, but you can get everything build finally

> One idea came up, what if I always build all projects on main but when deploy the docker images that hasn’t changed won’t be deployed

Yes, I would always run everything on the main branch. It's already merged, if it takes very long it doesn't matter, and it verifies all the code—even the parts that are hardly every touched.

[David Cardona](https://hashnode.com/@davidpccode)

[Dec 13, 2022](https://hashnode.com/posts/how-to-set-up-monorepo-build-in-gitlab-ci/60fd1d7318fbbb77c94672d6/comment/6397b64632e52b31f1387bac#reply-6398e4aa452f4e3f4cb65f8d)

Hi [Marcin Wosinek](https://hashnode.com/@marcin-wosinek)

Yes I think build everything on main is the real continuos integration. It ensure that everything no matter if was changed or not is working.

Thank you very much

[René Pardon](https://hashnode.com/@renepardon)

[Jul 12, 2022](https://hashnode.com/posts/how-to-set-up-monorepo-build-in-gitlab-ci/60fd1d7318fbbb77c94672d6/comment/62cd35633ba400c1d12e4892)

I really like your approach. Just have one question:

How can I manually trigger an explicit sub-project with this? For example I want to run only backend-build from within the Gitlab Interface or just frontend-deploy without triggering lets say 100 other jobs.

[Marcin Wosinek](https://hashnode.com/@marcin-wosinek)

[Jul 12, 2022](https://hashnode.com/posts/how-to-set-up-monorepo-build-in-gitlab-ci/60fd1d7318fbbb77c94672d6/comment/62cd35633ba400c1d12e4892#reply-62cd7fa78e6c0fc1acab464c)

I think you could achieve it by adding some variable/flag that introduces another level of control over what and when runs. It could complicate your set-up though, so I'm uncertain if it's a good idea.

I'm interested in learning more about GitLab CI cases that people try building—you can write a description of what you have now, and how would you like to change it, mail me at marcin.wosinek@gmail.com, and then we can meet at half-an-hour call.

[René Pardon](https://hashnode.com/@renepardon)

[Jul 12, 2022](https://hashnode.com/posts/how-to-set-up-monorepo-build-in-gitlab-ci/60fd1d7318fbbb77c94672d6/comment/62cd35633ba400c1d12e4892#reply-62cd82883ba400c1d12e57c1)

I switched our microservice infrastructure to a monorepo and it contains a websocket server, api gateway, a bunch of backend services and two frontends for now. I asked because at some point you might want to build only specific jobs or pipelines. E.g. when creating a new version / tag. In that case I don’t want to run all the code quality stuff over and over again. Just the build jobs to tag a new Docker image version of all services and frontends. [Marcin Wosinek](https://hashnode.com/@marcin-wosinek)

[Jordan Hugh McKimm](https://hashnode.com/@jhmck)

[Jun 8, 2022](https://hashnode.com/posts/how-to-set-up-monorepo-build-in-gitlab-ci/60fd1d7318fbbb77c94672d6/comment/62a03f1ccfaf9d6954b15523)

This is a very nice solution, much more elegant than something I've had on the go for the past year. Thanks for sharing!
