A pipeline library function behaves differently depending on which agent loads it. Why might that be?
AdvancedScenarioJenkins Shared Libraries, Credentials and Security
Answer
Situation read → Library code runs in the controller's CPS engine; only sh/bat steps run on agents.
What I'd do →
- Check whether the logic touches the filesystem with
new File(...)(controller-side) instead ofreadFile/fileExists(agent-side). - Replace java.io calls with pipeline steps, and keep non-serializable objects out of CPS variables or isolate them in
@NonCPSmethods. - Test with JenkinsPipelineUnit and a real agent.
Why → Controller-vs-agent semantics in Jenkins Groovy are a common source of subtle bugs.
Interview tip → NotSerializableException is the symptom to mention.
More on Jenkins Shared Libraries, Credentials and Security
Ten teams copy the same 80-line "build and push image" stage. What do you do?BeginnerA shared library change broke 50 pipelines at once. How do you prevent a repeat?AdvancedA pipeline needs an AWS secret key and a DB password. How do you provide them without exposing them in logs?BeginnerCredentials are stored in Jenkins; the security team wants no long-lived cloud keys at all.AdvancedA developer asks for admin access to Jenkins to "fix their job". How do you handle it?BeginnerA pipeline from a fork PR should not be able to read production credentials.Intermediate