DevOps / GitLab CI Basics Interview Questions
What are GitLab CI/CD variables and what types are available?
CI/CD variables are key-value pairs that make values available to jobs. They are used to configure jobs without hardcoding values, store secrets safely, and pass information between pipeline components.
| Type | Where defined | Use case |
|---|---|---|
| Predefined variables | Set automatically by GitLab | Pipeline metadata: $CI_COMMIT_SHA, $CI_COMMIT_BRANCH |
| Project variables | Settings > CI/CD > Variables | Project-specific secrets: API keys, passwords |
| Group variables | Group > Settings > CI/CD > Variables | Shared secrets across projects in a group |
| Instance variables | Admin area > CI/CD > Variables | Shared across the entire GitLab instance |
| .gitlab-ci.yml variables | variables: keyword in YAML | Non-secret config values |
# Defining variables in .gitlab-ci.yml variables: DATABASE_URL: "postgres://localhost/mydb" # available to all jobs DEPLOY_ENV: "staging" build-job: variables: NODE_ENV: "production" # job-level variable (overrides global) script: - echo "Branch: $CI_COMMIT_BRANCH" - echo "Commit: $CI_COMMIT_SHA" - echo "DB: $DATABASE_URL" - echo "Node env: $NODE_ENV"
Security settings for project/group variables:
- Masked - value is hidden in job logs (must be a single line, no spaces)
- Protected - variable only available to jobs running on protected branches or tags
- Expanded - controls whether
$VARreferences within the value are expanded
More Related questions...