What if you could magically pass files between Jenkins steps without lifting a finger?
Why Stash and unstash for passing data in Jenkins? - Purpose & Use Cases
Imagine you are building a software project with multiple steps in Jenkins. One step creates files, and the next step needs those files to continue. Without a way to share data, you have to manually copy files between steps or store them somewhere else.
Manually copying files between steps is slow and easy to forget. It can cause errors if files are missing or outdated. Also, managing file locations and cleanup becomes a headache, making your pipeline fragile and hard to maintain.
Using stash and unstash lets Jenkins automatically save files from one step and restore them in another. This keeps your pipeline clean and reliable, so you don't worry about where files are or if they are available.
sh 'cp build/output.zip ../next-step/' sh 'ls ../next-step/output.zip'
stash name: 'buildFiles', includes: 'build/output.zip' unstash 'buildFiles' sh 'ls build/output.zip'
It enables smooth and error-free sharing of files between different parts of your Jenkins pipeline.
When building a mobile app, you compile the app in one step and then run tests in another. Stash and unstash let you pass the compiled app files easily without manual copying.
Manual file sharing between steps is slow and error-prone.
Stash and unstash automate saving and restoring files in Jenkins pipelines.
This makes pipelines cleaner, faster, and more reliable.