DevOps / GitLab CI Basics Interview Questions
What is the 'needs' keyword in GitLab CI/CD and what problem does it solve?
The needs keyword creates a directed acyclic graph (DAG) of job dependencies, allowing jobs to start as soon as their specific dependencies are complete - rather than waiting for the entire previous stage to finish. This reduces total pipeline time significantly.
stages: - build - test - deploy build-frontend: stage: build script: npm run build artifacts: paths: [dist/] build-backend: stage: build script: go build -o api ./cmd artifacts: paths: [api] # Without needs: test-frontend must wait for BOTH build jobs to finish # With needs: test-frontend starts as soon as build-frontend is done test-frontend: stage: test needs: - build-frontend # only waits for this specific job script: npm test test-backend: stage: test needs: - build-backend # only waits for this specific job script: go test ./... deploy: stage: deploy needs: - test-frontend - test-backend script: ./deploy.sh
Key behaviours with needs:
- Jobs with
needscan run out of stage order -needsoverrides stage sequencing - A job with
needs: [](empty list) starts immediately when the pipeline creates - By default, a job with
needsdownloads artifacts from the listed jobs - Set
artifacts: falsein needs to skip downloading artifacts
More Related questions...