A monorepo has 12 services and every commit rebuilds all of them. How do you build only what changed in Jenkins?
IntermediateScenarioJenkins Pipelines and Agents
Answer
Situation read → No change detection.
What I'd do →
- Use
when { changeset 'services/payments/**' }on each service stage. - For PRs,
changesetcompares against the change request target; for non-PR builds usegit diff --name-only HEAD~1in a script and compute the set. - For larger repos, adopt a tool that understands the dependency graph (Bazel, Nx, Turborepo).
Why → Build time and cost scale with the change, not the repo size.
Interview tip → Mention shared libraries: a change in common/ must trigger every dependent service.
More on Jenkins Pipelines and Agents
Your team still builds jobs by clicking through Freestyle jobs in the Jenkins UI. A new service is starting. What do you set up instead?BeginnerA Jenkins build takes 40 minutes because unit tests, linting and security scans run one after another. How do you speed it up?BeginnerBuilds queue for 20 minutes during the morning rush, but the Jenkins nodes are mostly idle at night. What do you do?IntermediateA build works on agent A but fails on agent B with "command not found: mvn". How do you stop this class of problem?BeginnerYou need a pipeline to build a branch automatically on push without polling. How do you wire it?BeginnerOnly the main branch should deploy; feature branches and PRs should only build and test. How do you express this?Beginner