Prasa2166
Prasa2166

Reputation: 479

Gitlab CI - unique build number

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

Answers (4)

Turalyon
Turalyon

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

Pietro Di Bello
Pietro Di Bello

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

Sam
Sam

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

VonC
VonC

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 internally
  • CI_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 internally
  • CI_RUNNER_ID 8.10 0.5 The unique id of runner being used

Upvotes: 2

Related Questions