Interview Prep/CI/CD/Jenkins Pipelines and Agents

A deploy stage must run only if the previous stage produced a specific artifact, and pass its version along. How do you share data between stages?

IntermediateScenarioJenkins Pipelines and Agents
Answer

Situation read → Stages may run on different agents, so the workspace is not shared.

What I'd do →

  1. Pass small values through env.APP_VERSION = readFile('version.txt').trim().
  2. Pass files with stash name: 'dist', includes: 'dist/**' and unstash 'dist' in the later stage.
  3. For large or long-lived artifacts, publish to Nexus/Artifactory and pass only the coordinates.

Why → Stash is meant for small files within one run; a registry is the real source of truth.

Interview tip → Say "build once, promote the same artifact" - never rebuild per environment.

All CI/CD questions

More on Jenkins Pipelines and Agents