When Pipeline was first conceived it was natural to begin with Groovy as the
foundation. Jenkins already had an embedded Groovy scripting engine with a console
to interact with all parts of Jenkins and Groovy is a great language for creating
a custom Domain-Specific Language (DSL). The
Job-DSL,
plugin for Jenkins was also written in Groovy. This plugin lets you automate the
creation and editing of any job in Jenkins, including Pipelines.
Pipeline initially introduced key pipeline-specific concepts such as node
,
stage
, parallel
, and extension points to allow plugins to add other steps
to the DSL but, otherwise didn’t restrict the use of Groovy. This original syntax
for creating Pipelines is now referred to as "Scripted Pipeline" and includes
full programmatic control to allow scripting continuous delivery pipelines in Groovy.
This givesPipeline creators tremendous flexibility in defining a pipeline and allows it to
be extended via Shared Libraries or plugins.
|
Due to the need to serialize all variables for durability some Groovy
idioms are not fully supported yet. See
JENKINS-27421
and
JENKINS-26481
for more information.
|
Writing Pipelines with Scripted Pipeline syntax, however, does require at least
some proficiency with Groovy. Requiring all team members that touch the application’s
Pipeline to understand Groovy limits the ability for full-participation in
code-review, audits, and editing of the Pipeline as part of the application code.
Enter "Declarative Pipeline" syntax.
Declarative Pipeline syntax was created to extend Pipeline to users of all experience
levels and complement Scripted Pipeline syntax. As the name implies, it is intended
to enable declarative programming
for defining Pipelines as opposed to the imperative programming
provided by Scripted Pipeline. While it is still a DSL written
on top of Groovy, Declarative Pipeline is a limited to a pre-defined structure
that is much more specific to continuous delivery. This allows all stakeholders
to help create, edit, review, and audit the application’s Pipeline.
Scripted Pipeline and Declarative Pipeline both use the same underlying Pipeline
execution engine and both are fully-supported. You can use whichever you prefer
in any of your Pipelines and even combine them when needed. All examples in this handbook will show
both a Declarative Pipeline version and Scripted Pipeline version for your reference.