Skip to main content
In this lesson we explore GitLab’s predefined CI/CD variables—auto-generated environment variables that provide contextual information about jobs, pipelines, repositories, and more. Leveraging these variables makes your pipelines flexible and secure by avoiding hardcoded values. For a complete list of all predefined variables, see the GitLab Documentation on Predefined CI/CD Variables.

Categories of Predefined Variables

Inspecting All Available Variables

To view every environment variable supplied to a CI job, add a job that runs the export command:
The image shows a GitLab documentation page listing predefined CI/CD variables, including their names, versions, applicable runners, and descriptions. The sidebar contains navigation links for various GitLab features and settings.

1. Creating a New GitLab Project

  1. Navigate to your GitLab instance and click New project.
  2. Select Create blank project, choose a group (e.g., demos-group), set visibility to Public, and initialize with a README.
  3. Clone the repository locally or open it in the Web IDE.
The image shows a GitLab interface for creating a new blank project, with fields for project name, URL, and visibility settings. Options for initializing a repository with a README and enabling security testing are also visible.
Create a .gitlab-ci.yml file at the root of your project:
Commit and push your changes to trigger the pipeline:

2. Pipeline Overview

Once pushed, GitLab triggers a pipeline named Exploring Predefined Variable Pipeline. By default, all jobs run in the test stage and execute in parallel:
The image shows a GitLab pipeline interface with a running pipeline titled "Exploring Predefined Variable Pipeline," displaying three jobs in progress.

2.1 export_variable_job

This job dumps all environment variables. Here’s a truncated output:
Running export will print all environment variables, including sensitive tokens. Ensure your job logs are protected.

2.2 generic_predefined_variables

This job echoes commonly used variables to illustrate dynamic scripting:
Use these variables to customize your jobs based on commit metadata and pipeline context.

2.3 merge_request_predefined_variables

This job attempts to print merge-request–specific variables:
Merge request variables are only populated in pipelines triggered by Merge Requests. In direct pushes, these remain empty.
For more on Merge Request CI/CD variables, see the GitLab Merge Request Variables documentation.
The image shows a GitLab documentation page detailing predefined variables for merge request pipelines, including variable names, GitLab versions, runners, and descriptions. The sidebar on the left lists various sections related to CI/CD variables.

Watch Video