In my .gitlab-ci.yml
, I would like to give an incremental ID to every pipeline executed, but only relative to the merge request (the pipeline-ID is too large for my purposes), so the first pipeline will have a 0 (or 1, depending how I can get this number), the second a 1 (or 2), etc.
I've thought about using the number of root pipelines executed at that moment (I'm not sure how to name them, I mean the pipelines launched on a push, tag, etc., but not the downstream ones). I refer to this value:
I have found a solution using the API (see the answer below), but I would like to know if there is any better way to do it (I'm new in GitLab CI and probably I've just killed a fly with a sledgehammer).