GitLab CI predefined variables 💲
Tags: gitlab, ci, git, development
Published: 2021-03-12 16:51:49

---
title: GitLab CI predefined variables 💲
published: true
date: 2021-03-05 00:15:00 UTC
tags: gitlab, ci, git, development
canonical_url: https://www.benjaminrancourt.ca/gitlab-ci-predefined-variables
cover_image: https://www.benjaminrancourt.ca/temp/gitlab-ci-predefined-variables.2000.jpg
---
If you are implementing or enhancing a GitLab CI pipeline, you can use some of their [**predefined variables**](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). But, do you remember of what their values look like? Personally, not really. Unfortunately, the official documentation does not provide yet some examples of values, except for [some of them](https://docs.gitlab.com/ee/ci/variables/README.html#list-all-environment-variables). 😐

One way to know the available **CI variables** is to add the `printenv` command to any step, but I got tired of doing it whenever I looked for new ways to improve some pipelines. So I decided to create this post to provide me the informations I regularly seek! 👑

**Note** : some values have been changed to filter out information that may be sensitive. 🦉

Enjoy!

## CI

### CI config

```dotenv
CI_CONFIG_PATH=.gitlab-ci.yml
CI_DEFAULT_BRANCH=master
```

### CI build

```dotenv
CI_BUILD_BEFORE_SHA=ba2bb0ce23562f2d0800c333d1431063314214ad
CI_BUILD_ID=1027609276
CI_BUILD_NAME=printenv-sort
CI_BUILD_REF=1251f7ab188f7077b96c45ecf729dda8d080e084
CI_BUILD_REF_NAME=master
CI_BUILD_REF_SLUG=master
CI_BUILD_STAGE=install
CI_BUILD_TOKEN=xxxxxxxxxxxxxxxxxxxx
```

### CI commit

```dotenv
CI_COMMIT_BEFORE_SHA=ba2bb0ce23562f2d0800c433d1431063314214ad
CI_COMMIT_BRANCH=master (if running as not-detached, this variable does'nt exits)
CI_COMMIT_DESCRIPTION=
CI_COMMIT_MESSAGE=Merge remote-tracking branch 'origin/master'
CI_COMMIT_REF_NAME=master
CI_COMMIT_REF_PROTECTED=true
CI_COMMIT_REF_SLUG=master
CI_COMMIT_SHA=1251f7ab1568f7077b96c45ecf729dda8d080e084
CI_COMMIT_SHORT_SHA=1251f76b
CI_COMMIT_TIMESTAMP=2021-02-12T16:36:07-05:00
CI_COMMIT_TITLE=Merge remote-tracking branch 'origin/master'
```

### CI environment

When using the following YAML section:

```dotenv
  environment:
    name: production
    url: https://www.benjaminrancourt.ca

CI_ENVIRONMENT_NAME=production
CI_ENVIRONMENT_SLUG=production
CI_ENVIRONMENT_URL=https://www.benjaminrancourt.ca
```

### CI job

```dotenv
CI_JOB_ID=1027609276
CI_JOB_IMAGE=registry.gitlab.com/ben/tools/git-rsync:1.0.0
CI_JOB_JWT=eyJhbGciOiJSUzI1NiIsImtpZCI6IjRpM3NGRTdzeHFOUE9UN0ZkdmNHQTFaVkdHSV9yLXRzRFhuRXVZVDRacUUi[...]
CI_JOB_NAME=printenv-sort
CI_JOB_STAGE=install
CI_JOB_STATUS=running
CI_JOB_TOKEN=xxxxxxxxxxxxxxxxxxxx
CI_JOB_URL=https://gitlab.com/ben/printenv/-/jobs/1027609476
```

## CI merge request

If there is an open merge request, the environment variable named `CI_OPEN_MERGE_REQUESTS` appears:

```dotenv
CI_OPEN_MERGE_REQUESTS=ben/printenv!1
```

If we are launch a [**detached pipeline**](https://docs.gitlab.com/ee/ci/merge_request_pipelines/) with the following rule `- if: $CI_MERGE_REQUEST_IID`, a lot of variables are now defined:

```dotenv
CI_MERGE_REQUEST_DIFF_BASE_SHA=8a472061972cce6e4654fcec1627960f637f1bfc
CI_MERGE_REQUEST_DIFF_ID=143730685
CI_MERGE_REQUEST_EVENT_TYPE=detached
CI_MERGE_REQUEST_ID=88414052
CI_MERGE_REQUEST_IID=1
CI_MERGE_REQUEST_PROJECT_ID=24216056
CI_MERGE_REQUEST_PROJECT_PATH=ben/printenv
CI_MERGE_REQUEST_PROJECT_URL=https://gitlab.com/ben/printenv
CI_MERGE_REQUEST_REF_PATH=refs/merge-requests/1/head
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=tests
CI_MERGE_REQUEST_SOURCE_BRANCH_SHA=
CI_MERGE_REQUEST_SOURCE_PROJECT_ID=24216086
CI_MERGE_REQUEST_SOURCE_PROJECT_PATH=ben/printenv
CI_MERGE_REQUEST_SOURCE_PROJECT_URL=https://gitlab.com/ben/printenv
CI_MERGE_REQUEST_TARGET_BRANCH_NAME=master
CI_MERGE_REQUEST_TARGET_BRANCH_SHA=
CI_MERGE_REQUEST_TITLE=Testing branches
```

### CI pipeline

```dotenv
CI_PIPELINE_ID=275658478
CI_PIPELINE_IID=50
CI_PIPELINE_SOURCE=push
CI_PIPELINE_URL=https://gitlab.com/ben/printenv/-/pipelines/275658478
```

If the pipeline is created with a **[schedule](https://docs.gitlab.com/ee/ci/pipelines/schedules.html)**:

```dotenv
CI_PIPELINE_SOURCE=schedule
```

### CI project

```dotenv
CI_PROJECT_CONFIG_PATH=.gitlab-ci.yml
CI_PROJECT_DIR=/builds/ben/printenv
CI_PROJECT_ID=24216486
CI_PROJECT_NAME=printenv
CI_PROJECT_NAMESPACE=ben
CI_PROJECT_PATH=ranb2002/printenv
CI_PROJECT_PATH_SLUG=ben-printenv
CI_PROJECT_REPOSITORY_LANGUAGES=javascript,shell
CI_PROJECT_ROOT_NAMESPACE=ben
CI_PROJECT_TITLE=printenv
CI_PROJECT_URL=https://gitlab.com/ben/printenv
CI_PROJECT_VISIBILITY=private
```

### CI registry

```dotenv
CI_REGISTRY=registry.gitlab.com
CI_REGISTRY_PASSWORD=xxxxxxxxxxxxxxxxxxxx
CI_REGISTRY_USER=gitlab-ci-token
CI_REPOSITORY_URL=https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.com/ben/printenv.git
```

### CI runner

```dotenv
CI_RUNNER_DESCRIPTION=shared-runners-manager-4.gitlab.com
CI_RUNNER_EXECUTABLE_ARCH=linux/amd64
CI_RUNNER_ID=44949
CI_RUNNER_REVISION=d8cb88a0
CI_RUNNER_SHORT_TOKEN=72989761
CI_RUNNER_TAGS=gce, east-c, shared, docker, linux, ruby, mysql, postgres, mongo, git-annex
CI_RUNNER_VERSION=13.9.0-rc1
```

### CI server

```dotenv
CI_SERVER=yes
CI_SERVER_HOST=gitlab.com
CI_SERVER_NAME=GitLab
CI_SERVER_PORT=443
CI_SERVER_PROTOCOL=https
CI_SERVER_REVISION=8cb7781ba75
CI_SERVER_TLS_CA_FILE=/builds/ben/printenv.tmp/CI_SERVER_TLS_CA_FILE
CI_SERVER_URL=https://gitlab.com
CI_SERVER_VERSION=13.9.0-pre
CI_SERVER_VERSION_MAJOR=13
CI_SERVER_VERSION_MINOR=9
CI_SERVER_VERSION_PATCH=0
```

## GitLab

### User

```dotenv
GITLAB_USER_EMAIL=noreply@benjaminrancourt.ca
GITLAB_USER_ID=1
GITLAB_USER_LOGIN=ben
GITLAB_USER_NAME=Benjamin Rancourt
```

## Versions

The following environment variables may depend on the image used.

```dotenv
GIT_VERSION=v2.30.0
NODE_VERSION=15.8.0-buster
YARN_VERSION=1.22.5
```