Chapter 7. Declarative Pipelines
In this part of the book, we’re going to be talking about another evolution in Jenkins pipelines—Declarative Pipelines. Declarative Pipelines allow users to define a pipeline in a way similar to how they would define jobs in the traditional Jenkins web forms. By this we mean:
-
There is a well-defined, enforced structure. (You can think of this like the sections on the pages of a Jenkins web form.)
-
Defining a pipeline section is more about declaring the high-level steps/goals than defining the logic to accomplish it. (This is similar to filling in the fields in a Jenkins web form.)
-
Familiar Jenkins processing constructs are provided and don’t have to be emulated with programming. (For example, you have a way to do post-build processing and send notifications, as opposed to having to use
try-catch-finally
Groovy programming to handle this.) -
All of the above enable better validation and error checking. (Errors are identified and presented in the context of the expected structure and keywords, not just Groovy tracebacks.)
These features distinguish Declarative Pipelines from the alternative way of creating a pipeline that ties DSL steps and sections together with programming constructs (assignments, conditionals, etc.)—essentially writing a program. That style of free-form coding for a pipeline is what we call a “Scripted Pipeline.”
Both types of pipelines have their place, with advantages and disadvantages to each. Broadly speaking, Declarative ...
Get Jenkins 2: Up and Running now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.