DevOps / GitLab CI Basics Interview Questions
What are the most important predefined CI/CD variables in GitLab?
GitLab automatically sets dozens of predefined variables for every pipeline run. These provide jobs with information about the current commit, branch, pipeline, runner, and environment without any configuration.
| Variable | Value | Common use |
|---|---|---|
| $CI_COMMIT_SHA | Full commit SHA (40 chars) | Tagging Docker images |
| $CI_COMMIT_SHORT_SHA | First 8 chars of SHA | Short image tags, logs |
| $CI_COMMIT_BRANCH | Branch name | Conditional logic (if main...) |
| $CI_COMMIT_REF_NAME | Branch or tag name | Generic ref reference |
| $CI_COMMIT_REF_SLUG | Branch name, URL-safe (/ replaced with -) | Docker tags, URLs |
| $CI_PIPELINE_ID | Unique pipeline ID | Linking artifacts to pipelines |
| $CI_JOB_ID | Unique job ID | Unique artifact names |
| $CI_PROJECT_NAME | Repository name | Build labels |
| $CI_PROJECT_PATH | namespace/project | Registry image paths |
| $CI_REGISTRY | GitLab Container Registry URL | Docker login |
| $CI_REGISTRY_IMAGE | Full image path in registry | docker build/push |
| $GITLAB_USER_LOGIN | Username of who triggered pipeline | Audit logs |
| $CI_PIPELINE_SOURCE | What triggered the pipeline | Conditional job rules |
deploy: script: - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA . - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA - echo "Deployed by $GITLAB_USER_LOGIN from $CI_COMMIT_BRANCH"
More Related questions...