0
0
Jenkinsdevops~20 mins

Stash and unstash for passing data in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stash and Unstash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Jenkins pipeline snippet?
Consider this Jenkins pipeline stage snippet using stash and unstash:
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?
AError: No such file 'app.txt'
Bversion 1.0
CEmpty output
Dversion 2.0
Attempts:
2 left
💡 Hint
Remember that stash saves files from one stage and unstash restores them in another.
🧠 Conceptual
intermediate
1:30remaining
Why use stash and unstash in Jenkins pipelines?
Which of the following best explains the purpose of stash and unstash in Jenkins pipelines?
ATo pass files between different stages or nodes during a pipeline run
BTo permanently save files to the Jenkins master workspace
CTo create backups of the entire Jenkins workspace
DTo deploy files directly to production servers
Attempts:
2 left
💡 Hint
Think about how pipeline stages might run on different machines or agents.
Troubleshoot
advanced
2:00remaining
Why does unstash fail with 'No such stash' error?
You have this Jenkins pipeline snippet:
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?
AThe Deploy stage runs on a different node that cannot access the stash
BThe file 'output.log' was not created before stashing
CThe stash command must be inside the same stage as unstash
DThe stash name used in unstash does not match the stash name used in stash
Attempts:
2 left
💡 Hint
Check the exact names used in stash and unstash commands.
🔀 Workflow
advanced
1: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?
ACompile stage: unstash file; Test stage: create file, stash it
BCompile stage: create file; Test stage: read file without unstash
CCompile stage: create file, stash it; Test stage: unstash file, read it
DCompile stage: create file; Test stage: stash file, then unstash it
Attempts:
2 left
💡 Hint
Remember stash saves files and unstash restores them in later stages.
Best Practice
expert
2: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?
AOnly stash the necessary files using the 'includes' pattern to minimize data size
BAlways stash the entire workspace to ensure all files are available
CUse unstash multiple times in the same stage to improve speed
DAvoid using stash and unstash; copy files manually between nodes
Attempts:
2 left
💡 Hint
Think about how much data is transferred and stored temporarily.