Managing and Storing Data, Variables, and Secrets
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:
| Variable | Description | Example |
|---|---|---|
CI_COMMIT_SHA | The commit hash of the current commit. | 0600b2f708d21aff2e2f2bc076955e6d5bfb8621 |
CI_COMMIT_SHORT_SHA | The short commit hash of the current commit. | f7ddc6f |
CI_COMMIT_MESSAGE | The commit message of the current commit. | Add feature X |
CI_COMMIT_REF_NAME | The branch or tag name for which the pipeline runs. | main |
CI_COMMIT_REF_SLUG | The 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_TAG | The tag name for which the pipeline runs. | v1.0.0 |
CI_PIPELINE_ID | The unique ID of the pipeline. | 123456789 |
CI_PIPELINE_IID | The internal ID of the pipeline that starts at 1 for the project's first pipeline. | 4 |
CI_PIPELINE_SOURCE | The source of the pipeline (push, api, web, trigger ...) | push |
CI_JOB_ID |
Cloud Native CI/CD with GitLab
From Commit to Production ReadyEnroll now to unlock all content and receive all future updates for free.
