Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Managing and Storing Data, Variables, and Secrets
44%

Project Variables, Group Variables, and Instance Variables

In GitLab, you can set variables, whether they are secret or not, at the project, group, instance level, pipeline, or job level.

We have seen how to set a project-level variable. To set a group-level variable, go to Group -> Settings -> CI/CD -> Variables. These variables are available to all projects in the group. To set an instance-level variable, go to Admin Area -> Settings -> CI/CD -> Variables. These variables are available to all projects in the GitLab instance.

ℹ️ Instance-level variables are not available on all GitLab offerings (e.g., GitLab.com).

You can also set variables at the pipeline level or the job level. Let's see an example. Use the following code to create a .gitlab-ci.yml file that defines a pipeline variable and a job variable:

cat <$HOME/todo/app/.gitlab-ci.yml
image: python:3.12

variables:
  # Define a global variable
  PIPELINE_VARIABLE: "I'm the pipeline variable"

stages:
  - test-variables

test-1:
  variables:
    # Define a job variable
    JOB_VARIABLE: "I'm the job variable"

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Enroll now to unlock all content and receive all future updates for free.