Course contentsShow
← Cloud and Infrastructure
Lesson 1783 of 2,98937. JenkinsFree lesson

Declarative vs Scripted Pipeline Syntax

Understand the differences between Declarative and Scripted pipelines and when to use each approach.

Declarative vs Scripted Pipeline Syntax

What you'll learn: You'll understand the two pipeline syntax styles Jenkins offers and when to choose each one.

Jenkins provides two ways to write pipeline code: Declarative and Scripted. Think of Declarative as filling out a structured form—you work within predefined sections and rules. Scripted is like writing freeform code—you have full programming flexibility but must handle more details yourself.

Declarative Pipeline Syntax

Declarative pipelines use a fixed structure with specific blocks like pipeline, agent, stages, and steps. This approach enforces best practices and makes pipelines easier to read and maintain. It's the recommended starting point for most teams.

Structure: Requires a pipeline block at the top level, with nested stages containing individual stage blocks.

Best for: Standard CI/CD workflows, teams wanting consistency, and those who prefer guardrails over flexibility.

Scripted Pipeline Syntax

Scripted pipelines use Groovy programming language directly, wrapped in a node block. You write imperative code with full access to loops, conditionals, and complex logic without structural constraints.

Structure: Starts with node block, then you write Groovy code directly—complete programming freedom.

Best for: Complex workflows requiring dynamic behavior, advanced control flow, or when you need capabilities beyond Declarative's constraints.

Key Differences

  • Syntax validation: Declarative catches errors earlier with stricter syntax checking
  • Learning curve: Declarative is simpler for beginners; Scripted requires Groovy knowledge
  • Flexibility: Scripted offers more power; Declarative covers 95% of common needs
  • Readability: Declarative is more structured and self-documenting

Key Takeaway: Declarative pipeline syntax provides structure and safety for standard workflows, while Scripted syntax offers full programming flexibility for complex scenarios—start with Declarative unless you need advanced control flow.