Use this when using steps in Jenkins stages.
Steps · Jenkins
Steps are individual actions inside a Jenkins stage, such as sh, bat, git, junit or archiveArtifacts, provided by Jenkins core and plugins.
1. Steps are actions (sh, checkout, archiveArtifacts).
2. Fail on errors.
3. withCredentials for secrets.
4. timeout/retry wrappers.
5. Avoid string interpolation of secrets in Groovy (use single quotes).
step → action → result
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as controller/agent drift, plugin behavior changes, workspace contamination, credential leakage, retrying non-idempotent stages and green Pipeline status masking bad external state, choosing the cases most relevant to step action/shell/uses identity, inputs/env, condition, outputs and conclusion, plus correlation to the external side effect made by the step.
Step 2 Common mistakes Narrow the fault
shsteps that ignore exit codes.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Steps include sh, bat, git, junit, archiveArtifacts.
- They come from core and plugins.
- A non-zero exit fails the step.
- sh/bat/powershell steps with error handling — commands
- withCredentials blocks — secrets
- Step timeouts/retry — resilience
ReferenceWhy it matters1 section · depth on demand
In depth
Steps are the individual commands inside a stage: run a shell command, check out code, archive files, call a plugin. They are where the actual work happens, and each step's result decides whether the stage continues.
| Step | Use |
|---|---|
sh / bat / powershell | Run commands |
checkout scm | Get the source |
withCredentials | Expose secrets to a block |
archiveArtifacts | Keep build outputs |
junit | Publish test results |
retry(3) { } / timeout(5) { } | Wrap flaky or slow steps |
input | Manual approval |
sh fails the build on a non-zero exit code; use returnStatus: true or returnStdout: true only when you deliberately want to handle the result yourself.
def rc = sh(script: './check.sh', returnStatus: true)
if (rc == 2) { unstable('warnings found') }
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
The linked authority for bounded mechanics is Jenkins User Handbook; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Jenkins > Steps. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.jenkins.io/doc/ · confidence 94%