CI::Pipeline IIDs are not monotonic
Problem
If we have the following .gitlab-ci.yml
:
build:
script: echo "Hello World: $CI_PIPELINE_IID"
only: [branches]
And we push the following refspecs:
git push origin master
git push origin tag
git push origin master
The pushes will result in the following Pipelines with the IIDs:
- First push to
master
will create pipeline withbuild
and haveIID=1
, - The second push will not create pipeline,
- The third push will create pipeline with
build
and haveIID=3
.
This happens, as we optimisticly assume in 2. push that we gonna have pipeline,
and we allocate IID. However, this is not always true, as some pipelines are not
persisted. When pipeline is not persisted we gonna loose one IID
.
The solution
Rewind IID atomically if our IID is the latest one.
Edited by Elliot Rushton