I had a similar problem in one of my projects where I needed to manage multiple stages in a pipeline with parallel jobs, while also maintaining a sort of ‘Mutex’ across all stages.
Based on the already provided solutions here, I managed to get this work with Parent-child pipelines in combination with ‘resource_groups’.
To implement this I used a resource_group
for the parent job and configured it with strategy: depend
to ensure the parent job waits until the child-pipeline has finished. The benefit of this solution is, that is is independent of the runner-configuration and the child-pipeline configuration.
Parent-Pipeline .gitlab-ci.yml
:
stages:
- trigger
parent:
stage: trigger
resource_group: mutex
trigger:
include:
- local: '.gitlab-ci-child.yml'
strategy: depend
The actual pipeline configuration was moved to .gitlab-ci-child.yml
.