Interview Prep/CI/CD/Jenkins Pipelines and Agents

You inherit a 900-line Jenkinsfile that nobody dares to touch. What is your approach?

AdvancedScenarioJenkins Pipelines and Agents
Answer

Situation read → Copy-pasted logic, tangled state, no tests.

What I'd do →

  1. Freeze behaviour first: record current outputs and artifact checksums for a few representative builds.
  2. Extract shell steps into versioned scripts, and repeated stage blocks into a shared library function (vars/buildService.groovy).
  3. Move to Declarative where possible, keep scripted code only inside script {} blocks.
  4. Add unit tests with JenkinsPipelineUnit for the library, then refactor in small PRs.
  5. Compare artifacts before and after each change.

Why → Refactoring a pipeline safely means proving behaviour is unchanged, as with application code.

Interview tip → Emphasise small steps and a reference build, not a big-bang rewrite.

All CI/CD questions

More on Jenkins Pipelines and Agents