DevOpsInterviewPrep logo
← 🚀 Delivery & GitOps
Foundational

Jenkins workspaces, stashes and release artifacts: survive agent replacement

Distinguish agent workspaces, same-run stashes and retained release artifacts. Recover an interrupted pipeline without rebuilding a different candidate under an old approval.

TL;DR: An agent workspace is execution storage, and a stash is primarily a same-run transfer mechanism. Persist release candidates in retained artifact storage with a recorded identity. Agent recreation and stage restart must retrieve the approved bytes or require a new review.

A new agent does not inherit the old filesystem

A Pipeline can resume its control flow while a later stage runs on another agent. The logical build record and the worker's filesystem have different lifetimes. A checkout can recover source, but it cannot recover an unrecorded binary generated earlier, and rebuilding source can produce different bytes if dependencies or build inputs moved.

Separate three questions: where does a step execute, how do files reach the next stage, and how long must those files remain recoverable? A path such as dist/service.tar answers none of those without a producer and storage policy.

rendering diagram…

Pick the lifetime explicitly

StorageIntended useRecovery limit
WorkspaceRunning build's filesAgent loss or cleanup can remove it
stash / unstashFiles reused within one Pipeline runDefault lifecycle ends with the run
preserveStashesSupported Declarative restart casesConfigure retention and verify restart path
Archived/external artifactRetained build output or releaseDepends on retention, access and identity

The Jenkins basic-steps reference describes stash scope and the cost of compressing large stashes. External artifact managers can change the storage path and controller load; do not assume every installation moves files through the controller in the same way.

A same-run handoff

This Scripted Pipeline fixture requires two configured Linux agent labels. It transfers a tiny file, so it demonstrates a stash without treating it as a production artifact repository.

node('build-linux') {
  writeFile file: 'candidate.txt', text: 'fixture-17\n'
  stash name: 'candidate', includes: 'candidate.txt'
}
node('verify-linux') {
  deleteDir()
  unstash 'candidate'
  if (readFile('candidate.txt') != 'fixture-17\n') {
    error('Candidate mismatch')
  }
}

The fresh consumer workspace makes an accidental local-file dependency visible. Change the stash name and the handoff should fail; change the expected bytes and verification should fail. These outcomes require a Jenkins installation to observe. A local file comparison establishes only the content-check portion.

Keep approval bound to retained bytes

In a teaching release, build 71 produces digest D1, passes tests and waits for approval. Its agent disappears. Rebuilding the same commit later produces D2 after a dependency changes. The previous approval does not transfer to D2 merely because the Git SHA is unchanged.

Retrieve D1 from retained storage and verify its digest and evidence. If D1 is unavailable, declare that release unrecoverable under its existing approval. Build and test a new candidate, then obtain approval for that identity. Retention must cover the expected approval and recovery period, not just the typical successful build duration.

Declarative stage restart and controller resume are also different operations. Review the Pipeline syntax reference for preservation options and test the exact installed plugin behavior. A stage name in the UI cannot prove that every prerequisite file is retained.

Self-check: the controller resumes after restart and the build record still exists. Does that prove the lost agent's workspace is restored? No. Verify the file's retained source, transfer and identity separately.

Try the missing release file and the broader artifact promotion concept.

RELATED CONCEPTS
PRACTICE THIS IN REAL QUESTIONS