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 →
- Pass small values through
env.APP_VERSION = readFile('version.txt').trim(). - Pass files with
stash name: 'dist', includes: 'dist/**'andunstash 'dist'in the later stage. - 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.
More on Jenkins Pipelines and Agents
Your team still builds jobs by clicking through Freestyle jobs in the Jenkins UI. A new service is starting. What do you set up instead?BeginnerA Jenkins build takes 40 minutes because unit tests, linting and security scans run one after another. How do you speed it up?BeginnerBuilds queue for 20 minutes during the morning rush, but the Jenkins nodes are mostly idle at night. What do you do?IntermediateA build works on agent A but fails on agent B with "command not found: mvn". How do you stop this class of problem?BeginnerYou need a pipeline to build a branch automatically on push without polling. How do you wire it?BeginnerOnly the main branch should deploy; feature branches and PRs should only build and test. How do you express this?Beginner