CI/CD & GitHub Actions (50 Qs)•Part 3: Enterprise Scale, Compliance & Production Hardening (Senior / Staff)
Dynamic Matrix Strategies: How to generate matrix jobs dynamically from JSON outputs using expressions.
senior LevelCode ExamplecicdEnterprise Scale
In Simple Words: Instead of hardcoding matrix arrays in YAML, dynamic matrices compute the job list at runtime (e.g., finding all microservices modified in a pull request) and feed the JSON array into downstream parallel jobs.
yaml
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.filter.outputs.matrix }}
steps:
- id: filter
run: |
# Compute modified services as JSON array
echo 'matrix=["auth-service", "billing-service", "notification-service"]' >> "$GITHUB_OUTPUT"
build-services:
needs: detect-changes
strategy:
matrix:
service: ${{ fromJson(needs.detect-changes.outputs.services) }}
runs-on: ubuntu-latest
steps:
- run: echo "Building ${{ matrix.service }} in parallel"