How do you handle a monorepo where each service should build only when it changes?
AdvancedConceptMultibranch, organization folders & webhooks
Answer
Options:
- One multibranch job per service with its own script path and
when { changeset 'services/api/**' }on every stage (simple, but every push indexes every job). - One pipeline that computes changed paths (
git diff --name-only origin/main...HEAD) and builds a dynamicparallelmap for affected services. - A build tool that understands the graph (Nx, Bazel, Gradle) invoked once.
Note that changeset compares against the previous build of the branch, so the first build of a new branch sees no changeset and may skip everything; handle that case explicitly.
More on Multibranch, organization folders & webhooks
How does a multibranch pipeline work?BeginnerWhat is branch indexing and what triggers it?BeginnerWhat are the discovery traits in the GitHub branch source?IntermediateWhat does the fork PR trust setting protect against?AdvancedWhat environment variables are set for PR builds?BeginnerWhat is an organization folder?Intermediate