0
0
Jenkinsdevops~5 mins

Stash and unstash for passing data in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of stash in Jenkins pipelines?

stash saves files temporarily during a pipeline run so they can be used later in another stage or node.

Click to reveal answer
beginner
How does unstash complement stash in Jenkins?

unstash retrieves the files saved by stash so they can be used in a different stage or node.

Click to reveal answer
intermediate
Can stash and unstash be used to pass data between parallel stages?

Yes, stash and unstash allow sharing files between parallel or sequential stages in Jenkins pipelines.

Click to reveal answer
intermediate
What happens if you try to unstash a name that was never stashed?

Jenkins throws an error because it cannot find the stash with that name.

Click to reveal answer
beginner
Write a simple Jenkins pipeline snippet that stashes a file named output.txt and then unstashes it in the next stage.
stage('Save') {
  steps {
    writeFile file: 'output.txt', text: 'Hello'
    stash name: 'myFiles', includes: 'output.txt'
  }
}
stage('Use') {
  steps {
    unstash 'myFiles'
    sh 'cat output.txt'
  }
}
Click to reveal answer
What does the stash step do in Jenkins pipelines?
AStarts a new pipeline
BSaves files temporarily for later use in the pipeline
CRuns a shell command
DDeletes files from the workspace
Which step retrieves files saved by stash?
Astash
Barchive
Cunstash
Dcheckout
Can stash and unstash be used across different nodes in a Jenkins pipeline?
AOnly for parallel stages
BNo, only within the same node
COnly if nodes share the same workspace
DYes, they allow passing files between nodes
What will happen if you try to unstash a stash name that does not exist?
AJenkins throws an error and stops the pipeline
BJenkins ignores it silently
CJenkins creates an empty stash
DJenkins retries the stash
Which of these is a correct way to stash all files in the workspace?
Astash name: 'all', includes: '**/*'
Bstash name: 'all', excludes: '**/*'
Cunstash name: 'all'
Dstash name: 'all', files: '*'
Explain how stash and unstash help pass data between stages in Jenkins pipelines.
Think about how you might pack and unpack a suitcase to carry things between places.
You got /4 concepts.
    Describe a scenario where using stash and unstash is necessary in a Jenkins pipeline.
    Imagine you bake cookies in one kitchen and want to eat them in another kitchen.
    You got /4 concepts.