DevOps / Gitlab Interview questions
How do you write a multi-stage.gitlab-ci.yml pipeline?
A multi-stage pipeline defines an ordered list under stages, then assigns each job to one of those stages with the stage keyword. Jobs sharing a stage run in parallel; the pipeline moves to the next stage only once the current one finishes successfully.
stages: - build - test - deploy build-job: stage: build script: - docker build -t myapp:$CI_COMMIT_SHORT_SHA . unit-test: stage: test script: - npm run test:unit lint: stage: test script: - npm run lint deploy-staging: stage: deploy script: - ./deploy.sh staging environment: name: staging only: - main
Here, unit-test and lint both run in the test stage and execute in parallel, but neither starts until build-job succeeds. The environment key ties the deploy job to a tracked GitLab environment, and the only rule restricts deployment to the main branch so feature branches never trigger a staging deploy.
More Related questions...