DevOps / GitLab CI Basics Interview Questions
What are stages in GitLab CI/CD and how do you define them?
Stages control the order of execution in a pipeline. Jobs within the same stage run in parallel; stages themselves run sequentially. If any job in a stage fails, subsequent stages are not run (unless configured otherwise).
# Define stages at the top level of .gitlab-ci.yml stages: - build - test - deploy # Jobs reference their stage with the "stage" keyword build-job: stage: build script: - echo "Building..." test-unit: stage: test script: - echo "Running unit tests..." test-integration: stage: test # also in "test" stage - runs PARALLEL to test-unit script: - echo "Running integration tests..." deploy-job: stage: deploy script: - echo "Deploying..."
Default stages: GitLab provides default stages if you do not define a stages block. The built-in defaults are: .pre, build, test, deploy, .post. The special .pre stage always runs first (before any other stages) and .post always runs last.
| Stage | Behaviour |
|---|---|
| .pre | Always runs before all other stages - regardless of stages list order |
| .post | Always runs after all other stages |
More Related questions...