- https://www.jenkins.io/doc/book/pipeline/syntax/
- Type: reference
- Source: jenkins.io official documentation
TL;DR
Official reference for Jenkins Declarative and Scripted pipeline syntax: sections, directives, post conditions, when rules, parallel/matrix stages and the traps that go with them.
What it covers
Declarative is the structured, opinionated form wrapped in pipeline { }; Scripted is Groovy running top to bottom inside node { }. Both share the same engine and steps. A declarative pipeline is built from sections (agent, stages, steps, post) and directives (environment, options, parameters, triggers, tools, input, when).
Key takeaways
- Pick the agent per pipeline or stage:
any,none,label,docker,dockerfileorkubernetes. - Inject secrets safely with
environment { KEY = credentials('id') }; username/password credentials also expose_USRand_PSW. - React to results in
post:always,changed,fixed,regression,success,failure,unstable,aborted,cleanup(runs last). - Gate stages with
when:branch,tag,changeset,environment,expression, combined withnot,allOf,anyOf; addbeforeAgent trueto skip agent allocation. - Compose stages: nested sequential
stages,parallel(withfailFast true), ormatrixwithaxesandexcludes; a stage holds exactly one ofsteps,stages,parallelormatrix, and parallel cannot nest in parallel. - Schedule with
triggers:cron('H */4 * * 1-5'); useHto spread load. - Avoid the classic traps: no semicolons, a top-level
timeoutexcludes agent wait time but a stage one includes it, and awhenexpression returning the string"false"is still true.
Tools and concepts
| Item | Role in the page |
|---|---|
| Jenkins | The CI server whose Pipeline DSL is described |
| Declarative vs Scripted | The two syntaxes, same engine |
| Shared Libraries | Place for large script {} blocks because of the declarative size limit |
| Docker | Agent option for containerised builds |
When to use
- When writing or debugging a Jenkinsfile and you need the exact directive or option name.
- When deciding declarative vs scripted for a pipeline.
- When running parallel or sequential stages, see the specific questions in Sequential stages within parallel pipeline in Jenkins.
Caveats
- Reference, not a tutorial: examples are minimal and the page has no dedicated security section.
Jenkins DevOps Docker Sequential stages within parallel pipeline in Jenkins How to run multiple stages on the same node with declarative Jenkins pipeline Continue Jenkins pipeline past failed stage How do I schedule jobs in Jenkins