Interview Prep/CI/CD/Jenkins Shared Libraries, Credentials and Security

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 →

  1. Check whether the logic touches the filesystem with new File(...) (controller-side) instead of readFile/fileExists (agent-side).
  2. Replace java.io calls with pipeline steps, and keep non-serializable objects out of CPS variables or isolate them in @NonCPS methods.
  3. 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.

All CI/CD questions

More on Jenkins Shared Libraries, Credentials and Security