0
0
Jenkinsdevops~15 mins

Shell steps (sh, bat) in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Shell Steps in Jenkins Pipeline
📖 Scenario: You are setting up a Jenkins pipeline to automate simple shell commands. This will help you understand how to run shell scripts inside Jenkins jobs.
🎯 Goal: Build a Jenkins pipeline script that runs shell commands using sh steps on Linux or macOS, and bat steps on Windows agents.
📋 What You'll Learn
Create a Jenkins pipeline script with a pipeline block
Use a stage named Setup to run shell commands
Use sh step to run a Linux/macOS shell command
Use bat step to run a Windows batch command
Print the output of the commands in the Jenkins console
💡 Why This Matters
🌍 Real World
Jenkins pipelines automate software builds and deployments by running shell commands on build agents.
💼 Career
Knowing how to use <code>sh</code> and <code>bat</code> steps is essential for DevOps engineers to automate tasks across different operating systems.
Progress0 / 4 steps
1
Create a Jenkins pipeline with a pipeline block
Write a Jenkins pipeline script starting with a pipeline block and an empty agent any section.
Jenkins
Need a hint?

Start with pipeline { and add agent any inside it.

2
Add a stage named Setup
Inside the pipeline block, add a stages block with one stage named Setup.
Jenkins
Need a hint?

Add stages {} and inside it a stage('Setup') { steps { } } block.

3
Add a sh step to run echo Hello from Linux
Inside the steps block of the Setup stage, add a sh step that runs the command echo Hello from Linux.
Jenkins
Need a hint?

Use sh 'echo Hello from Linux' inside steps {}.

4
Add a bat step to run echo Hello from Windows
Below the sh step inside the steps block, add a bat step that runs the command echo Hello from Windows.
Jenkins
Need a hint?

Add bat 'echo Hello from Windows' below the sh step.