0
0
Jenkinsdevops~5 mins

Shell steps (sh, bat) in Jenkins - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Acmd
Bbat
Cpowershell
Dsh
Which step should you use to run Windows batch commands in Jenkins pipeline?
Ash
Bbat
Cbash
Dshell
How do you get the output of a shell command in Jenkins pipeline?
Abat(script: 'cmd', returnOutput: true)
Bsh('cmd')
Csh(script: 'cmd', returnStdout: true)
Dbat('cmd')
What happens if a shell command fails in Jenkins pipeline without error handling?
AThe pipeline step fails and build stops
BThe pipeline continues
CThe command is retried automatically
DThe error is ignored
Which of these is NOT a valid Jenkins pipeline shell step?
Acmd
Bbat
Cpowershell
Dsh
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.