DEV Community

Cover image for GitLab CI predefined variables ๐Ÿ’ฒ
Benjamin Rancourt
Benjamin Rancourt

Posted on • Originally published at benjaminrancourt.ca on

GitLab CI predefined variables ๐Ÿ’ฒ

If you are implementing or enhancing a GitLab CI pipeline, you can use some of their predefined variables. 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. ๐Ÿ˜

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

CI_CONFIG_PATH=.gitlab-ci.yml
CI_DEFAULT_BRANCH=master
Enter fullscreen mode Exit fullscreen mode

CI build

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
Enter fullscreen mode Exit fullscreen mode

CI commit

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'
Enter fullscreen mode Exit fullscreen mode

CI environment

When using the following YAML section:

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

CI_ENVIRONMENT_NAME=production
CI_ENVIRONMENT_SLUG=production
CI_ENVIRONMENT_URL=https://www.benjaminrancourt.ca
Enter fullscreen mode Exit fullscreen mode

CI job

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
Enter fullscreen mode Exit fullscreen mode

CI merge request

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

CI_OPEN_MERGE_REQUESTS=ben/printenv!1
Enter fullscreen mode Exit fullscreen mode

If we are launch a detached pipeline with the following rule - if: $CI_MERGE_REQUEST_IID, a lot of variables are now defined:

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
Enter fullscreen mode Exit fullscreen mode

CI pipeline

CI_PIPELINE_ID=275658478
CI_PIPELINE_IID=50
CI_PIPELINE_SOURCE=push
CI_PIPELINE_URL=https://gitlab.com/ben/printenv/-/pipelines/275658478
Enter fullscreen mode Exit fullscreen mode

If the pipeline is created with a schedule:

CI_PIPELINE_SOURCE=schedule
Enter fullscreen mode Exit fullscreen mode

CI project

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
Enter fullscreen mode Exit fullscreen mode

CI registry

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
Enter fullscreen mode Exit fullscreen mode

CI runner

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
Enter fullscreen mode Exit fullscreen mode

CI server

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
Enter fullscreen mode Exit fullscreen mode

GitLab

User

GITLAB_USER_EMAIL=noreply@benjaminrancourt.ca
GITLAB_USER_ID=1
GITLAB_USER_LOGIN=ben
GITLAB_USER_NAME=Benjamin Rancourt
Enter fullscreen mode Exit fullscreen mode

Versions

The following environment variables may depend on the image used.

GIT_VERSION=v2.30.0
NODE_VERSION=15.8.0-buster
YARN_VERSION=1.22.5
Enter fullscreen mode Exit fullscreen mode

Top comments (0)