A team needs the same pipeline for 25 microservices in one monorepo, but only changed services should build. Design it in Jenkins.
AdvancedScenarioShared libraries & multibranch
Answer
Situation read → One multibranch job, dynamic stages based on the diff.
What I'd do →
- Compute changed services:
def base = env.CHANGE_TARGET ? "origin/${env.CHANGE_TARGET}" : 'HEAD~1' def changed = sh(script: "git diff --name-only ${base}...HEAD | cut -d/ -f2 | sort -u", returnStdout: true).trim().split('\n') - Build a
parallelmap with one branch per changed service, each calling a library step. - Force all services to build on
mainnightly or when shared code (libs/) changes. - Cache dependencies per service via a repository manager.
Why → Dynamic parallel keeps one pipeline while avoiding 25 full builds per commit.
Interview tip → Mention that for very large monorepos a graph-aware build tool beats shell diffs.
More on Shared libraries & multibranch
A shared library change merged to `main` broke 200 pipelines within minutes. How do you prevent a repeat?IntermediateYou want to test a library branch against a real app pipeline without affecting anyone. How?BeginnerEvery app repo has its own pod YAML for builds, and they all drift. How do you standardize?IntermediateSecurity wants every pipeline to run a secret scan, even if teams forget to add it. How?AdvancedA multibranch project has 600 stale branch jobs and the folder page takes 30 seconds to load. What do you do?BeginnerA new org with 150 repositories wants Jenkins builds for every repo with a Jenkinsfile, without tickets to the platform team. What do you set up?Intermediate