Slide 1

Slide 1 text

Declarative Pipelines Andrew Bayer Arnaud Héritier

Slide 2

Slide 2 text

Arnaud Héritier • Long time Jenkins user and community member • August 2007 : My first discussion on the mailing list and my first ticket about Jenkins born Hudson 1.131 • Contributor on various plugins: • Maven, Xcode, Appaloosa, … • Member of the Jenkins infra team • I love to reboot confluence ☺ • Support Delivery Manager at CloudBees, Inc • I help our customers to get the best from Jenkins @aheritier aheritier

Slide 3

Slide 3 text

What is Declarative?

Slide 4

Slide 4 text

What is Declarative? ● A syntax for Jenkins Pipelines designed to… ○ Have smarter default behavior for most use cases ○ Make Pipelines more structured ○ Provide better error reporting and handling

Slide 5

Slide 5 text

Smarter default behavior ● Default SCM checkout ● Built with Docker and containers in mind from day one ● No more need for try/catch for notifications, etc ● More intuitive ways to specify job properties, triggers and parameters ● Streamlined syntax for conditional execution of stages

Slide 6

Slide 6 text

More structure in Pipelines ● Separate configuration from actual steps to be executed ● Everything happens in a stage ● Easier to look at any Declarative Pipeline and understand what it’s doing - more consistency! ● Enables round-tripping with the visual editor (more on this later!) ● Built with and for Blue Ocean visualization

Slide 7

Slide 7 text

Better error reporting ● Syntax and validation errors reported at the very beginning of the build ● No more waiting til a build has gone an hour to discover that you misspelled “timeout”! ● Errors report as compilation errors, pointing to the specific code or text that’s causing problems

Slide 8

Slide 8 text

Better error reporting ● Eliminates many potentially confusing stack traces (though not all!) ● Validates things like syntax, required configuration, step parameter types, and more

Slide 9

Slide 9 text

What happens to Scripted Pipeline? ● In short? Nothing. ● We’re now calling “traditional” Pipeline “Scripted Pipeline” to distinguish it from Declarative Pipeline ● All one execution engine behind the scenes ○ Declarative is built on top of Scripted Pipeline, not replacing it ○ Blue Ocean and Stage View don’t distinguish between a Scripted Pipeline or a Declarative Pipeline

Slide 10

Slide 10 text

What happens to Scripted Pipeline? ● Scripted Pipeline still used *inside* Declarative Pipeline in steps blocks, post blocks ○ You can copy the contents of a Declarative steps block into a Scripted Pipeline (inside a node block, of course!) and it’ll Just Work.

Slide 11

Slide 11 text

Why Declarative?

Slide 12

Slide 12 text

Why everyone should use Pipeline ● Durability ● Pipeline as Code ● More modern backend implementation ● More powerful and flexible than traditional Jenkins jobs

Slide 13

Slide 13 text

Benefits of Declarative for new users ● Lower barrier of entry than Scripted Pipelines ● Human readable ● Does not require Groovy-specific expertise ● Create and edit Declarative Pipelines via the UI Editor

Slide 14

Slide 14 text

Benefits of Declarative for existing users ● Uses same engine as Scripted, so existing investments still pay off ● Expand usage and usability ○ Less burden on “experts” ○ Easier empowerment of other users ● Easier collaboration and code review ● Lintable! ● Separation of Jenkins infrastructure-related configuration from steps to execute

Slide 15

Slide 15 text

Syntax Overview

Slide 16

Slide 16 text

© 2017 CloudBees, Inc. All Rights Reserved. 16 node { 
 try { stage('Build') { checkout scm docker.image('ubuntu').inside {
 sh 'mvn clean install' } } }
 catch(exc) { mail to:'[email protected]', subject:'FAILURE:' } finally { deleteDir() }
 } pipeline {
 agent { docker 'ubuntu' } stages {
 stage('Build') {
 steps {
 sh 'mvn clean install'
 }
 }
 }
 post {
 always {
 deleteDir()
 }
 failure {
 mail to:'[email protected]', subject:'FAILURE:' }
 }
 } Scripted Pipeline Declarative Pipeline

Slide 17

Slide 17 text

First example https://gist.github.com/abayer/ bd99a722aeee5077a16c4bfc6ed8f9a1

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Second example https://gist.github.com/abayer/ 01ca97caae06aeb2d8e3f71b3bc0b9a9

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Validation

Slide 30

Slide 30 text

Validation and linting ● Always happens at the beginning of a build ● If any validation errors are found, the build will fail before actually running anything ● Errors point to the problem area with line/column number and an error message, often with suggestions for what you may have intended

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

CLI and API support for linting

Slide 33

Slide 33 text

Blue Ocean

Slide 34

Slide 34 text

Blue Ocean visualization ● Some special smarts on both sides for optimized visualization ● Blue Ocean keeps built-in stages for things like checkout, Docker image prep, post-build actions out of your way unless there’s a problem ● Special marking of stages that have been skipped due to either an unsatisfied when condition or an earlier failed stage

Slide 35

Slide 35 text

Pipeline Visual Editor!

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

What’s next?

Slide 40

Slide 40 text

Declarative - Parallel stages stage('foo') { parallel { stage('first') { steps { echo "First branch" } } stage('second') { steps { echo "Second branch" } } } } https://issues.jenkins-ci.org/browse/JENKINS-41334

Slide 41

Slide 41 text

That’s a wrap!

Slide 42

Slide 42 text

Resources on Declarative • Documentation on https://jenkins.io/doc/ • Examples coming soon at https://github.com/ jenkinsci/pipeline-examples • Plugin source at https://github.com/jenkinsci/pipeline- model-definition-plugin

Slide 43

Slide 43 text

Questions?

Slide 44

Slide 44 text

Thanks!