Problem Statement
How do stages work in GitLab CI/CD?
Explanation
GitLab CI/CD organizes pipelines into stages that run sequentially. Default stages are build, test, and deploy, running in that order. Jobs within the same stage run in parallel (if multiple runners available), while stages wait for all jobs in previous stage to complete before starting. This structure enables parallel execution within stages while maintaining dependencies between stages.
Example:
```yaml
stages:
- build
- test
- deploy
build_app:
stage: build
script:
- make build
unit_tests:
stage: test
script:
- make test
integration_tests:
stage: test
script:
- make integration-test
deploy_prod:
stage: deploy
script:
- make deploy
```
Build stage completes first, then unit_tests and integration_tests run in parallel (both in test stage), finally deploy_prod runs. If any job fails, subsequent stages don't execute by default. Custom stages can be defined in any order. Understanding stage execution model is crucial for designing efficient pipelines.
