Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Managing and Storing Data, Variables, and Secrets
42%

Predefined Variables: Dynamic and Flexible Pipelines

In GitLab, there are some predefined variables that you can use in your pipelines. These variables are set by GitLab and are helpful for many reasons, one of which is to provide information about the pipeline, the job, the repository, and the environment.

To give you some examples, when you run a job, you may want to identify the current branch of the repository, the commit hash, the pipeline ID, the pipeline URL, the job ID, the job name, the job status, and many other pieces of information. These variables are useful for creating a dynamic and flexible pipeline that can adapt to different situations. Instead of writing code to get them, GitLab provides these variables for you. So in addition to this feature being helpful, it also opens the door to many possibilities and adaptations. You only have to read the value of the variable by referencing its name and use it in your pipeline.

Here are some examples - the list is not exhaustive:

VariableDescriptionExample
CI_COMMIT_SHAThe commit hash of the current commit.0600b2f708d21aff2e2f2bc076955e6d5bfb8621
CI_COMMIT_SHORT_SHAThe short commit hash of the current commit.f7ddc6f
CI_COMMIT_MESSAGEThe commit message of the current commit.Add feature X
CI_COMMIT_REF_NAMEThe branch or tag name for which the pipeline runs.main
CI_COMMIT_REF_SLUGThe branch or tag name for which the pipeline runs, lowercased, and with everything except 0-9 and a-z replaced with -.feature-x
CI_COMMIT_TAGThe tag name for which the pipeline runs.v1.0.0
CI_PIPELINE_IDThe unique ID of the pipeline.123456789
CI_PIPELINE_IIDThe internal ID of the pipeline that starts at 1 for the project's first pipeline.4
CI_PIPELINE_SOURCEThe source of the pipeline (push, api, web, trigger ...)push
CI_JOB_ID

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Enroll now to unlock all content and receive all future updates for free.