Challenge - 5 Problems
Stash and Unstash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Jenkins pipeline snippet?
Consider this Jenkins pipeline stage snippet using stash and unstash:
What will be printed in the Test stage?
stage('Build') {
steps {
writeFile file: 'app.txt', text: 'version 1.0'
stash name: 'appFiles', includes: 'app.txt'
}
}
stage('Test') {
steps {
unstash 'appFiles'
script {
def content = readFile('app.txt')
echo content
}
}
}What will be printed in the Test stage?
Attempts:
2 left
💡 Hint
Remember that stash saves files from one stage and unstash restores them in another.
✗ Incorrect
The 'app.txt' file is created and stashed in the Build stage. The Test stage unstashes it, so reading 'app.txt' prints its content 'version 1.0'.
🧠 Conceptual
intermediate1:30remaining
Why use stash and unstash in Jenkins pipelines?
Which of the following best explains the purpose of stash and unstash in Jenkins pipelines?
Attempts:
2 left
💡 Hint
Think about how pipeline stages might run on different machines or agents.
✗ Incorrect
Stash and unstash allow temporary storage and transfer of files between pipeline stages or nodes, enabling sharing of build artifacts.
❓ Troubleshoot
advanced2:00remaining
Why does unstash fail with 'No such stash' error?
You have this Jenkins pipeline snippet:
When running, the Deploy stage fails with:
What is the most likely cause?
stage('Build') {
steps {
writeFile file: 'output.log', text: 'log data'
stash name: 'logs', includes: 'output.log'
}
}
stage('Deploy') {
steps {
unstash 'logfiles'
}
}When running, the Deploy stage fails with:
No such stash 'logfiles'What is the most likely cause?
Attempts:
2 left
💡 Hint
Check the exact names used in stash and unstash commands.
✗ Incorrect
The stash was saved with the name 'logs' but unstash tries to retrieve 'logfiles', causing the error.
🔀 Workflow
advanced1:30remaining
Identify the correct sequence to share files between stages using stash/unstash
You want to share a file created in the 'Compile' stage with the 'Test' stage in a Jenkins pipeline. Which sequence of steps is correct?
Attempts:
2 left
💡 Hint
Remember stash saves files and unstash restores them in later stages.
✗ Incorrect
Files must be created and stashed in the first stage, then unstashed in the next stage to be accessible.
✅ Best Practice
expert2:30remaining
What is the best practice when using stash to pass large files between Jenkins pipeline stages?
When passing large files between stages using stash and unstash, which practice helps avoid performance issues?
Attempts:
2 left
💡 Hint
Think about how much data is transferred and stored temporarily.
✗ Incorrect
Stashing only needed files reduces data transfer and storage, improving pipeline speed and resource use.