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.