Can I trigger project pipelines when a new package is created?

I have microservices in different projects that all use a private python library hosted in my GitLab PyPI package registry. Whenever I complete an MR for my python library, my pipeline builds the package and uploads it to the registry. When this happens, I would like for the projects that use this library to automatically update the requirements.txt with the new package version and auto-generate an MR with those changes.

To do this, I need my project pipelines to trigger when that package is pushed. Is this possible to do? The pipeline could run a simple script to edit the requirements.txt file, and another script to create an MR using the GitLab API, both of these seem to be reasonably easy.

What I would like is for projects using the library to discover there is a new version, somehow. If I keep a list of all projects using the library in the library’s CI, I could use the GitLab API to trigger a pipeline on each.

To me this sounds like a need for dependabot? I’ve never implemented one on GitLab, I have no idea if some plugins or something already exists for this kind of problem.

But, I have two ideas for you.

a) How many projects exactly depend on this library? If it’s not much, you could play around with downstream pipelines (Parent-child) - e.g. after your publish package job is done (in python library project), you could trigger a pipeline in your project pipeline (one or more), forwarding the version number or some other variables that you could use as input in the project pipeline.

b) If you have more then e.g. 5 projects (and growing) this might not be optimum, because you would always need to add more downstream jobs for every project using the library. In that case, maybe you could try out pipeline subscription - e.g your project could “subscribe” to your library project pipeline and basically trigger a new pipeline every time the library project pipeline on tag on default branch is completed successfully. I never tried this out myself, neither I can find docs about it. But you can do this in project Settings > CI/CD > Pipeline Subscriptions.

Good luck! And let us know if you have found a working solution :slight_smile:

1 Like