Skip to content

CICD-382 · Build changed services only ​

Encyclopedia · Monorepo and large-scale build engineering · All snippets

Previous · CICD-381 · Next · CICD-383

1. Where it fits ​

  • Placement CI matrix run step.
  • Prerequisites trusted checkout with the base ref fetched and pinned package manager or build tool.
  • Platforms local-linux, github-actions, gitea-actions.
  • Parameters SERVICE.

2. Copy the snippet ​

bash
case "${SERVICE:?}" in api|worker|frontend) docker build -t "ci/$SERVICE" "services/$SERVICE";; *) exit 2;; esac

3. How it works ​

The case pattern limits build targets to approved service names. A planned target becomes one Docker context and a matching local image tag.

The matrix produces one approved image context per service.

flowchart TD
  N1["Changed-service planner"]
  N2{"Service allowed"}
  N1 --> N2
  N3["Build selected context"]
  N2 -->|Yes| N3
  N4["Reject input"]
  N2 -->|No| N4
  classDef trigger fill:#EFF6FF,stroke:#0540F2,color:#0A0A0A
  classDef build fill:#CCFBF1,stroke:#0D9488,color:#0A0A0A
  classDef test fill:#EEF2FF,stroke:#4F46E5,color:#0A0A0A
  classDef gate fill:#FEF3C7,stroke:#D97706,color:#0A0A0A
  classDef security fill:#EDE9FE,stroke:#7C3AED,color:#0A0A0A
  classDef deploy fill:#D1FAE5,stroke:#059669,color:#0A0A0A
  classDef fail fill:#FEE2E2,stroke:#DC2626,color:#0A0A0A
  class N1 trigger
  class N2 security
  class N3 build
  class N4 fail

4. Verify the result ​

Drive the job with a changed-service matrix, allowlist contexts and build downstream dependents separately.

Validation syntax-validated (Bash parse). Status definitions.