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.