DevOps / GitLab CI Basics Interview Questions
What is a CI/CD job in GitLab and what are the required keywords?
A job is the fundamental unit of work in a GitLab pipeline. It defines a set of shell commands to run, where to run them, and under what conditions. Jobs run independently on runners and produce a job log accessible in the GitLab UI.
# Minimum viable job (only "script" is required): hello-world: script: - echo "Hello, World!" # Full job with common keywords: build-app: stage: build image: node:20-alpine before_script: - npm ci script: - npm run build after_script: - echo "Build complete" artifacts: paths: - dist/ rules: - if: $CI_COMMIT_BRANCH == "main"
| Keyword | Purpose | Required? |
|---|---|---|
| script | Commands to execute - the job's main work | Yes |
| stage | Which stage this job belongs to | No (defaults to 'test') |
| image | Docker image to use as the job environment | No |
| before_script | Commands that run before script (setup) | No |
| after_script | Commands that run after script (cleanup, always runs) | No |
| artifacts | Files/dirs to save and pass to later jobs | No |
| rules | Conditions that determine when the job runs | No |
| tags | Specify which runner to use by tag | No |
Jobs must be defined at the top level of the YAML file. Any YAML key not matching a reserved keyword is treated as a job name. Job names starting with a dot (e.g. .setup) are hidden jobs - they don't run but can be used as templates.
More Related questions...