A library uses a class that stores the build's config in a static field. Builds started at the same time see each other's values. Why and how do you fix it?
AdvancedScenarioShared libraries & multibranch
Answer
Situation read → Library classes are loaded once per library version per controller classloader context and static fields are shared across concurrent builds.
What I'd do →
- Remove static mutable state; pass config as method arguments or instance fields.
- Create instances per build (
new Config(this, params)) and keep themSerializable. - Add a JenkinsPipelineUnit test that simulates two configs.
Why → Static fields behave like global variables across builds, and CPS resume makes them even less predictable.
Interview tip → Say "library code must be stateless across builds".
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