Interview Prep/Jenkins/Shared libraries & multibranch

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 →

  1. 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')
    
  2. Build a parallel map with one branch per changed service, each calling a library step.
  3. Force all services to build on main nightly or when shared code (libs/) changes.
  4. 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.

All Jenkins questions Roadmap: Jenkins

More on Shared libraries & multibranch