Use this when writing declarative Jenkins pipelines.
Declarative Pipeline
A declarative pipeline uses Jenkins' structured syntax — pipeline, agent, stages, steps, post — which is easier to read and validate than scripted pipelines and is the recommended style.
1. Declarative pipelines: structured, validated syntax.
2. Options for timeouts/concurrency.
3. when for conditions.
4. post for cleanup/notifications.
5. Preferred over scripted.
declarative stages → steps → post actions
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 pipeline model validation, stages/steps/directives, post conditions, agent/options/environment and the difference between Pipeline syntax and target state.
Step 2 Common mistakes Narrow the fault
- Mixing declarative and scripted syntax without need.
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.
- Declarative syntax: pipeline, agent, stages, steps, post.
- It is validated before running.
- It is the recommended style.
- pipeline { agent … stages { … } } — structure
- options { timeout(); disableConcurrentBuilds() } — controls
- post { always/failure } — notifications
ReferenceWhy it matters1 section · depth on demand
In depth
Declarative pipeline is Jenkins' structured pipeline syntax: a fixed set of sections (agent, stages, steps, post, options, when, environment) that Jenkins validates before running. It is easier to read and review than scripted pipeline and is the recommended choice for most pipelines.
Key sections:
| Section | Purpose |
|---|---|
agent | Where the pipeline or stage runs |
environment | Environment variables and credentials |
options | Timeouts, retries, build discarding |
when | Conditional stages (branch, tag, expression) |
parallel | Run stages concurrently |
post | Actions on success, failure, always |
When logic outgrows declarative syntax, use a script { } block sparingly or move the logic to a shared library rather than switching the whole pipeline to scripted syntax.
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
The linked authority for bounded mechanics is Jenkins Handbook — Pipeline Syntax; 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 > Declarative Pipeline. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.jenkins.io/doc/book/pipeline/syntax/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For pipeline model validation, stages/steps/directives, post conditions, agent/options/environment and the difference between Pipeline syntax and target state, prefer typed fields and stable IDs over human presentation text.