Skip to main content

Working with Predefined Variables

1. Using Project Variables (CI_PROJECT_*)

Variable Description Example Value
CI_PROJECT_ID Unique identifier for the project 12345
CI_PROJECT_NAME Name of the project my-app
CI_PROJECT_PATH Full path of the project including namespace group/subgroup/my-app
CI_PROJECT_PATH_SLUG URL-safe version of the project path group-subgroup-my-app
CI_PROJECT_URL URL to the project in GitLab https://gitlab.example.com/group/subgroup/my-app
CI_PROJECT_NAMESPACE Namespace of the project (group or user) group/subgroup
CI_PROJECT_DESCRIPTION Description of the project A sample application
CI_PROJECT_VISIBILITY Visibility level of the project (public, internal, private) private

Example: Using CI_PROJECT_NAME in a script

echo "Building project: $CI_PROJECT_NAME"

2. Using Pipeline Variables (CI_PIPELINE_*)

Variable Description Example Value
CI_PIPELINE_ID Unique ID of the pipeline 12345
CI_PIPELINE_IID Internal ID of the pipeline within the project 67890
CI_PIPELINE_SOURCE Source that triggered the pipeline (e.g., push, schedule) push
CI_PIPELINE_URL URL to the pipeline in GitLab https://gitlab.example.com/group/project/pipelines/12345
CI_PIPELINE_CREATED_AT Timestamp when the pipeline was created 2026-04-05T10:00:00Z

Example: Using CI_PIPELINE_ID in a Script

echo "Running pipeline with ID: $CI_PIPELINE_ID"

3. Using Job Variables (CI_JOB_*)

Variable Description Example Value
CI_JOB_ID Unique identifier for the job 123456789
CI_JOB_NAME Name of the job as defined in the CI configuration build
CI_JOB_STAGE Stage the job belongs to test
CI_JOB_STATUS Current status of the job (running, success, failed) success
CI_JOB_STARTED_AT Timestamp when the job started 2025-04-05T10:00:00Z
CI_JOB_DURATION Duration of the job in seconds 60

Example: Using CI_JOB_ID in a script

echo "Job ID is: $CI_JOB_ID"

Example: Using CI_JOB_NAME to conditionally run a task

script:
  - "echo 'Running job: $CI_JOB_NAME'"

4. Using Commit Variables (CI_COMMIT_*)

Variable Description Example Value
CI_COMMIT_SHA Full length commit SHA 1234567890abcdef1234567890abcdef12345678
CI_COMMIT_SHORT_SHA Shortened commit SHA (8 characters) 12345678
CI_COMMIT_REF_NAME Branch or tag name main
CI_COMMIT_REF_PROTECTED Indicates if the branch is protected false
CI_COMMIT_TITLE First line of the commit message feat: add new feature
CI_COMMIT_MESSAGE Full commit message feat: add new feature\n\nThis adds a new feature to the project.
CI_COMMIT_AUTHOR Author of the commit John Doe <john.doe@example.com>
CI_COMMIT_TIMESTAMP Timestamp of the commit 2024-01-01T12:00:00Z

Example: Using Commit Variables in a Job

job_name:
  script:
    - echo "Commit SHA: $CI_COMMIT_SHA"
    - echo "Branch: $CI_COMMIT_REF_NAME"
    - echo "Author: $CI_COMMIT_AUTHOR"

5. Using Merge Request Variables (CI_MERGE_REQUEST_*)

Variable Description Example Value
CI_MERGE_REQUEST_ID Unique ID of the merge request 12345
CI_MERGE_REQUEST_IID Internal ID of the merge request 12345
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME Name of the source branch feature/new-feature
CI_MERGE_REQUEST_TARGET_BRANCH_NAME Name of the target branch main
CI_MERGE_REQUEST_SOURCE_PROJECT_URL URL of the source project https://gitlab.example.com/group/project
CI_MERGE_REQUEST_TITLE Title of the merge request Implement new feature
CI_MERGE_REQUEST_DESCRIPTION Description of the merge request This MR implements a new feature...
CI_MERGE_REQUEST_AUTHOR_ID ID of the author who created the merge request 123456
CI_MERGE_REQUEST_AUTHOR_NAME Name of the author who created the merge request John Doe
CI_MERGE_REQUEST_AUTHOR_EMAIL Email of the author who created the merge request john.doe@example.com

Example: Using Merge Request Variables in a Pipeline

script:
  - echo "Merge Request ID: $CI_MERGE_REQUEST_ID"
  - echo "Source Branch: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
  - echo "Target Branch: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
  - echo "Title: $CI_MERGE_REQUEST_TITLE"
Note: These variables are only available in pipelines triggered by merge request events.

6. Using Tag Variables

Variable Description Example Value
CI_COMMIT_TAG Set to the tag name if the pipeline was triggered by a tag push. v1.0.0
CI_COMMIT_TAG_SHORT Shortened version of the tag name without any prefix or suffix. 1.0.0
CI_COMMIT_TAG_MESSAGE Message associated with the tag if available. Release version 1.0.0

Example: Using Tag Variables in a Job

deploy:
  stage: deploy
  script:
    - echo "Deploying version $CI_COMMIT_TAG"
    - echo "Tag message: $CI_COMMIT_TAG_MESSAGE"
Note: These variables are only available when the pipeline is triggered by a tag push. They will be empty otherwise.

7. Using Environment Variables (CI_ENVIRONMENT_*)

Variable Description Example Value
CI_ENVIRONMENT_NAME Name of the environment staging
CI_ENVIRONMENT_SLUG Slugified name of the environment staging
CI_ENVIRONMENT_URL URL of the environment https://staging.example.com

Example: Setting environment variable in a job

job_name:
  script:
    - echo "Environment: $CI_ENVIRONMENT_NAME"
    - echo "URL: $CI_ENVIRONMENT_URL"

8. Using Runner Variables (CI_RUNNER_*)

Variable Description Example Value
CI_RUNNER_ID Unique identifier for the runner 12345678
CI_RUNNER_NAME Name of the runner as configured my-runner-name
CI_RUNNER_EXECUTOR Executor used by the runner (e.g., shell, docker) shell
CI_RUNNER_TAGS Tags assigned to the runner (comma-separated) linux,amd64
CI_RUNNER_SHORT_TOKEN Short token used for authentication a1b2c3d4

Example: Using Runner Variables in a Script

#!/bin/bash
echo "Runner ID: $CI_RUNNER_ID"
echo "Runner Name: $CI_RUNNER_NAME"
echo "Executor Type: $CI_RUNNER_EXECUTOR"

9. Using Registry Variables (CI_REGISTRY_*)

Variable Description Example Value
CI_REGISTRY Registry URL for the project registry.gitlab.com
CI_REGISTRY_IMAGE Full image name with registry URL registry.gitlab.com/group/project/image:tag
CI_REGISTRY_USER Username for registry authentication gitlab-ci-token
CI_REGISTRY_PASSWORD Password for registry authentication ...

Example: Pushing to GitLab Container Registry

docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
docker build -t $CI_REGISTRY_IMAGE .
docker push $CI_REGISTRY_IMAGE

10. Using Server Variables (CI_SERVER_*)

Variable Description Example Value
CI_SERVER_VERSION Full version of the GitLab instance 17.2.0
CI_SERVER_REVISION Git commit hash of the GitLab instance abc123de
CI_SERVER_NAME Name of the GitLab instance GitLab
CI_SERVER_URL Base URL of the GitLab instance https://gitlab.example.com
CI_SERVER_HOST Hostname of the GitLab instance gitlab.example.com
CI_SERVER_PORT Port used by the GitLab instance 443
CI_SERVER_PROTOCOL Protocol used by the GitLab instance https
CI_SERVER_TLS_CERT_FILE Path to the TLS certificate file (if available) /etc/gitlab/ssl/cert.pem
CI_SERVER_TLS_KEY_FILE Path to the TLS key file (if available) /etc/gitlab/ssl/key.pem
CI_SERVER_TLS_CA_FILE Path to the CA certificate file (if available) /etc/gitlab/ssl/ca.pem

Example: Using CI_SERVER_VERSION in a script

#!/bin/bash
echo "Running on GitLab version: $CI_SERVER_VERSION"

Was this article helpful?