What is Step in Jenkins Pipeline: Definition and Examples
step is a single task or command executed as part of the pipeline process. Steps are the building blocks that perform actions like running scripts, checking out code, or sending notifications within a stage.How It Works
Think of a Jenkins Pipeline as a recipe for building and delivering software. Each step is like an instruction in that recipe, telling Jenkins exactly what to do next. For example, one step might be to fetch the latest code from a repository, while another step might compile the code.
Steps run in order inside stages, which group related tasks together. This is similar to how a cooking recipe groups steps into preparation, cooking, and plating. Each step completes before the next one starts, ensuring the pipeline flows smoothly.
Example
This example shows a simple Jenkins Pipeline with steps that print messages and run shell commands.
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Starting the build process'
sh 'echo Running a shell command'
echo 'Build process finished'
}
}
}
}When to Use
Use steps whenever you want Jenkins to perform a specific action in your pipeline. This includes tasks like compiling code, running tests, deploying applications, or sending notifications.
For example, in a real project, you might use steps to:
- Check out source code from Git
- Run unit tests with a testing tool
- Build a Docker image
- Deploy the application to a server
- Notify the team via email or chat
Steps make your pipeline flexible and powerful by letting you automate every part of your software delivery process.
Key Points
- A
stepis a single action inside a Jenkins Pipeline. - Steps run inside
stagesto organize the pipeline. - Common steps include
echo,sh,checkout, and more. - Steps execute sequentially to automate build, test, and deploy tasks.