Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 560
Prasa2166 Avatar asked Sep 05 '25 03:09

Prasa2166


2 Answers

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

like image 94
Pietro Di Bello Avatar answered Sep 08 '25 15:09

Pietro Di Bello


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

like image 29
Sam Avatar answered Sep 08 '25 13:09

Sam