Use this when writing Groovy scripted pipelines.
Scripted Pipeline
A scripted pipeline is written in Groovy inside node { } blocks, giving full programming flexibility but less structure and validation than declarative pipelines.
1. Scripted pipelines are flexible Groovy.
2. Harder to maintain and validate.
3. Sandbox and script approvals.
4. Use only when needed.
5. Prefer declarative + shared libraries.
Groovy script → pipeline
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 Groovy-based execution model, node/stage/step control flow, exception handling and keeping imperative flexibility from hiding target-state verification.
Step 2 Common mistakes Narrow the fault
- Complex Groovy logic that is hard to maintain.
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.
- Full flexibility.
- Less validation.
- Harder to maintain.
- node { … } Groovy — scripted
- In-process script approval — sandbox
- Migration plan to declarative — maintainability
ReferenceWhy it matters1 section · depth on demand
In depth
Scripted pipeline is Jenkins' original pipeline syntax: plain Groovy code inside a node { } block. It offers full programming flexibility — loops, dynamic stage generation, complex conditions — at the cost of readability and fewer guardrails.
node('linux') {
stage('Checkout') { checkout scm }
def sites = ['oslo', 'aarhus', 'malmo']
for (s in sites) {
stage("Deploy ${s}") { sh "./deploy.sh ${s}" }
}
}
Use it when a pipeline really needs dynamic behaviour; otherwise prefer declarative. Groovy in pipelines runs in a sandbox — unapproved method calls fail with RejectedAccessException and need administrator approval, which is a security review point, not a formality.
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 > Scripted 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 Groovy-based execution model, node/stage/step control flow, exception handling and keeping imperative flexibility from hiding target-state verification, prefer typed fields and stable IDs over human presentation text.