CI/CD Fundamentals

Protected Variables

< >

4. Protected Variables

As recommended before, GitLab allows you to mark certain secret variables as “protected.” The Protected variables are allowed only to be used by the pipelines that run on protected branches  or protected tags , adding an extra layer of security.

  • Protected Variables: Only available in protected branches or tags, and their values are masked in job logs.

To mark a variable as protected:

  1. Navigate to your project in GitLab.
  2. Go to Settings > CI/CD.
  3. Expand the Variables section.
  4. Click on Add variable.
  5. Enter the Key and Value for the variable.
    • We will create a variable for this example:
      • Key: PROTECTED_VAR
      • Value: ThisIsProtectedValue
  6. Set the scope of the variable (Project-Level or Group-Level).
  7. Mark the variable as Protected.
  8. Click Add variable to save the protected variable.

*Note: Alternatively, GitLab has HashiCorp Vault integration for secure secret management.