Reputation: 479
Is there any unique number in Gitlab CI which can be used as build number as we use in Jenkins. I came to know about the variable "CI_PIPELINE_IID" but the problem with this variable is, it updates for all branches and there is no such variable exist for each branch.
Upvotes: 28
Views: 45441
Reputation: 9
Yeah,it's a reasonable request for many situations. Someone has issued it before, please refer to: https://gitlab.com/gitlab-org/gitlab/-/issues/23844. But it seems that it has not added this so far.
Upvotes: 0
Reputation: 521
We solved the same issue using the variable $CI_PIPELINE_IID
, which is defined as
The project-level IID (internal ID) of the current pipeline. This ID is unique only within the current project.
And is quite similar to Jenkins' $BUILD_NUMBER
See also https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#variables-reference
Upvotes: 20
Reputation: 6112
It looks like CI_COMMIT_SHA
or CI_COMMIT_SHORT_SHA
are great candidates for this as they give you a reference to the commit it was built from.
For example, if you want to use it as a docker image tag, use
docker build . -t myapp:$CI_COMMIT_SHA
Note that earlier versions of Gitlab (version 8.x) use CI_BUILD_TAG
More variables on: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#variables-reference
Upvotes: 7
Reputation: 1323135
You can check if any of the other ids "CI variables" might work in your case:
CI_JOB_ID
9.0 all The unique id of the current job that GitLab CI uses internallyCI_PIPELINE_ID
8.10 all The unique id of the current pipeline that GitLab CI uses internally (one I)CI_PROJECT_ID
all all The unique id of the current project that GitLab CI uses internallyCI_RUNNER_ID
8.10 0.5 The unique id of runner being usedUpvotes: 2