Managing CI/CD Variables and Secrets
Introduction
Section titled βIntroductionβCI/CD variables let you pass configuration and secrets to pipeline jobs without hardcoding values in the repository.
Add Variables
Section titled βAdd Variablesβ- Navigate to Settings > CI/CD > Variables.
- Click Add variable and provide a Key and Value.
- Set options for Protected, Masked, or Environment scope as needed.
- Save the variable.
Use Variables in .gitlab-ci.yml
Section titled βUse Variables in .gitlab-ci.ymlβjob: script: - echo "Running as $MY_VAR"Variables are available as environment variables within jobs.
Best Practices
Section titled βBest Practicesβ- Mask secrets to prevent exposure in logs.
- Protect variables used only in protected branches or production environments.
- Rotate sensitive values periodically and remove unused variables.