Recall & Review
beginner
What is the purpose of the
sh step in a Jenkins pipeline?The
sh step runs shell commands on Unix/Linux agents within a Jenkins pipeline.Click to reveal answer
beginner
How do you run a batch script on a Windows agent in Jenkins pipeline?
Use the
bat step to run batch commands or scripts on Windows agents.Click to reveal answer
beginner
What is the difference between
sh and bat steps in Jenkins?sh runs shell commands on Unix/Linux agents, while bat runs batch commands on Windows agents.Click to reveal answer
intermediate
How can you capture the output of a shell command in Jenkins pipeline using
sh?Use
def output = sh(script: 'command', returnStdout: true).trim() to capture and trim the output.Click to reveal answer
intermediate
What happens if a command run by
sh or bat fails in Jenkins pipeline?The pipeline step fails and the build stops unless you handle errors explicitly.
Click to reveal answer
Which Jenkins pipeline step runs shell commands on Linux agents?
✗ Incorrect
The
sh step is used to run shell commands on Unix/Linux agents.Which step should you use to run Windows batch commands in Jenkins pipeline?
✗ Incorrect
The
bat step runs batch commands on Windows agents.How do you get the output of a shell command in Jenkins pipeline?
✗ Incorrect
Use
sh(script: 'cmd', returnStdout: true) to capture output from shell commands.What happens if a shell command fails in Jenkins pipeline without error handling?
✗ Incorrect
By default, a failed shell or batch command causes the pipeline step to fail and stops the build.
Which of these is NOT a valid Jenkins pipeline shell step?
✗ Incorrect
cmd is not a Jenkins pipeline step; use bat for Windows batch commands.Explain how to run shell commands on Linux and batch commands on Windows in Jenkins pipelines.
Think about the agent OS and matching step.
You got /3 concepts.
Describe how to capture the output of a shell command in Jenkins pipeline and why it might be useful.
Focus on the <code>sh</code> step options.
You got /3 concepts.