Template
Monorepo Matrix Pipeline
Run selective tests for multiple services with rules and explicit downstream dependencies.
Best for polyglot monorepos.
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == "main"'
stages:
- prepare
- test
- deploy
prepare_shared:
stage: prepare
image: node:22-alpine
script:
- npm ci
artifacts:
paths:
- node_modules/
test_web:
stage: test
needs:
- job: prepare_shared
artifacts: true
script:
- npm run test:web
test_api:
stage: test
needs:
- job: prepare_shared
artifacts: true
script:
- npm run test:api
deploy_changed:
stage: deploy
dependencies:
- prepare_shared
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
script:
- echo "deploy changed services"