- https://www.jenkins.io/doc/pipeline/tour/running-multiple-steps/#running-multiple-steps
- Type: tutorial
- Source: jenkins.io Pipeline tour
TL;DR
A Jenkins stage can run many steps in order: sh/bat for commands, retry and timeout as wrappers, and post for cleanup and notifications.
Summary
A pipeline is made of steps; each succeeds and moves on, or fails and fails the pipeline. Use sh on Linux/macOS and bat on Windows, with triple quotes for multiline scripts. Wrapper steps change behaviour: retry(n) repeats and timeout(time, unit) stops runaway steps, and they nest. The post section runs outcome-based actions, with a scripted equivalent based on try/catch/finally.
Key takeaways
- Command steps:
sh '...'(Unix) andbat '...'(Windows);'''for multiline. - Fail fast: any failed step fails the pipeline.
- Wrap flaky steps:
timeout(time: 3, unit: 'MINUTES') { retry(5) { sh './flakey-deploy.sh' } }caps total retry time. - Post conditions:
always,success,failure,unstable,changed. - Scripted equivalent uses
try/catch/finallyandcurrentBuild.result; rethrow the exception after reporting.
Tools and concepts
| Item | Role in the page |
|---|---|
| Jenkins | Pipeline steps and wrappers |
| Jenkins pipeline Syntax | Full reference for the same constructs |
| Linux | sh runs shell commands on Unix agents |
When to use
- When writing your first multi-step stage.
- When you need retry plus timeout for a flaky step.
- When translating
postconditions to scripted pipelines.
Caveats
- Introductory tour page; deeper options are in the syntax reference.
Jenkins DevOps Jenkins pipeline Syntax How do I schedule jobs in Jenkins Jenkins SSH Pipeline Steps