Orchestrating the Continuous Delivery 
Process in Jenkins with Workflow 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
1
Today’s Presenters 
Cyrille Le Clerc 
Director, Product Management 
cleclerc@cloudbees.com 
@cyrilleleclerc 
Steve Harris 
SVP, Products 
sharris@cloudbees.com 
@stevengharris 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
2
Using WebEx 
Questions? 
Submit via the Q&A window 
at any time during the 
presentation. 
We will cover Q&A at the 
end of the presentation. 
Session is being recorded. 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
3
Agenda 
• Con=nuous 
Delivery 
• Jenkins 
& 
Con=nuous 
Delivery 
• Workflow 
in 
Jenkins 
Today 
• The 
New 
Jenkins 
Workflow 
Engine 
• Jenkins 
Workflow 
Syntax 
Card 
• Possible 
Futures 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
4
Continuous Delivery 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
5
Continuous Delivery 
• “Reliable 
So+ware 
Releases 
through 
Build, 
Test, 
and 
Deployment 
Automa=on” 
• DONE 
= 
Shippable 
into 
Produc=on 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
6
Continuous Integration Steps 
Con$nuous 
Integra$on 
Source Code 
Quality Analysis 
Compile & 
Unit Tests 
Binaries 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
7
Continuous Delivery Steps 
Con$nuous 
Delivery 
DEV 
DEV 
QA 
OPS 
Source Code 
Quality Analysis 
Compile & 
Unit Tests 
Binaries 
Perfs Environment 
Func Test Environment 
UAT Environment 
Production Environment 
GO LIVE! 
Release! 
Staging Environment 
8
Continuous Delivery Pipeline 
Continuous Delivery Pipeline 
Compile & 
Unit Tests 
Perfs Tests 
Selenium Tests Deploy UAT 
Sonar Analysis 
Deploy Staging Deploy Production 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
9
Jenkins: Hub of Continuous Delivery 
• Connect 
the 
dots 
• It 
is 
the 
process 
Source Code 
Perfs Environment 
Func Test Environment 
UAT Environment 
Binaries 
Quality Analysis 
Compile & 
Unit Tests 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
10
CI/CD with Jenkins and Vagrant and Puppet 
puppet 
deployment 
module 
java 
code 
Dev Environment 
vagrant provision 
puppet apply 
war file + puppet manifests & 
modules 
petclinic.war 
Puppet Agent 
App. Server 
QA Environment 
petclinic.war 
Puppet Agent 
App. Server 
Prod Environment 
petclinic.war 
Puppet Agent 
App. Server 
war file + puppet manifests & modules 
Puppet 
Master 
Puppet 
Master 
OPS 
war file + puppet manifests & modules 
Jenkins 
builds 
war 
file 
and 
Puppet 
modules 
and 
deploys 
via 
Vagrant
CI/CD with Jenkins and Vagrant and Puppet 
puppet 
deployment 
module 
java 
code 
Dev Environment 
notification 
vagrant provision 
puppet apply 
war file + puppet manifests & 
modules 
petclinic.war 
Puppet Agent 
App. Server 
QA Environment 
petclinic.war 
Puppet Agent 
App. Server 
Prod Environment 
petclinic.war 
Puppet Agent 
App. Server 
notification 
war file + puppet manifests & modules 
Puppet 
Master 
Puppet 
Master 
OPS 
war file + puppet manifests & modules 
Jenkins 
builds 
war 
file 
and 
Puppet 
modules 
and 
deploys 
via 
Vagrant
Jenkins – Puppet Integration
CD Pipeline è Workflow 
Continuous Delivery Pipeline 
Compile & 
Unit Tests 
Perfs Tests 
Selenium Tests Deploy UAT 
Sonar Analysis 
Deploy Staging Deploy Production 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
14
What We Need 
• Complex 
pipelines 
involving 
mul=ple 
stages 
• Non-­‐sequen$al 
logic 
such 
as 
loops, 
forks 
… 
• Long-­‐running 
builds 
must 
survive 
outages 
• Interac$ons 
with 
humans 
including 
pauses, 
input 
• Restartable 
builds 
in 
case 
of 
transient 
errors 
• Reusable 
defini$ons 
to 
avoid 
duplica=on 
• Comprehensible 
scripts 
with 
one 
clear 
defini=on 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
15
Most Existing Workflow In Jenkins Today 
• Job 
Chaining 
• Build 
Flow 
Plugin 
• Build 
Pipeline 
Plugin 
• Build 
Delivery 
Pipeline 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
16
Most Existing Workflow In Jenkins Today 
• Many 
atomic 
jobs 
• Hard 
to 
share 
variables/state 
between 
jobs 
• Limited 
logic 
• Mix 
build 
triggers, 
parameterized 
build 
… 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
17
Jenkins Workflow Engine 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
18
Simplifying Our Sample Workflow 
Compile & 
Unit Tests 
Perfs Tests 
Selenium Tests Deploy UAT 
Sonar Analysis 
Deploy Staging Deploy Production 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
19
Simplifying Our Sample Workflow 
Compile & 
Unit Tests 
Perfs Tests 
Selenium Tests Deploy UAT 
Sonar Analysis 
Deploy Staging Deploy Production 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
20
What We Need 
• Complex 
pipelines 
involving 
mul=ple 
stages 
• Non-­‐sequen$al 
logic 
such 
as 
loops, 
forks 
… 
• Long-­‐running 
builds 
must 
survive 
outages 
• Interac$ons 
with 
humans 
including 
pauses, 
input 
• Restartable 
builds 
in 
case 
of 
transient 
errors 
• Reusable 
defini$ons 
to 
avoid 
duplica=on 
• Comprehensible 
scripts 
with 
one 
clear 
defini=on 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
21
New Workflow Syntax 
22
Production Release Available NOW! 
• Jenkins 
OSS 
– Workflow 
1.0 
released 
December 
3 
• Beta 
out 
since 
May, 
with 
great, 
engaged 
feedback 
• Install 
Workflow: 
Aggregator 
in 
LTS 
1.580.x 
or 
a 
later 
weekly 
release 
• Jenkins 
Enterprise 
by 
CloudBees 
– Automa=cally 
available 
as 
of 
the 
14.11 
release 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
23
Demo Time! 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
24
Key Features 
• En=re 
flow 
is 
one 
concise 
Groovy 
script 
– For 
loops, 
try-­‐finally, 
fork-­‐join 
… 
• Can 
restart 
Jenkins 
while 
flow 
is 
running 
• Allocate 
slave 
nodes 
and 
workspaces 
– As 
many 
as 
you 
want, 
when 
you 
want 
• Stages 
throdle 
concurrency 
of 
builds 
• Human 
input/approval 
integrated 
into 
flow 
• Standard 
project 
concepts: 
SCM, 
ar=facts, 
plugins 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
25
Groovy DSL vs. Graphical Workflow 
• Familiar 
control 
flow 
construc=on 
• Familiar 
“tools” 
for 
building 
abstrac=ons 
Func=ons, 
classes, 
variables, 
… 
• Workflow 
in 
version 
control 
• As 
opposed 
to: 
Graphical 
workflow 
designer 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
26
Project Setup 
• One 
workflow 
is 
defined 
as 
a 
job 
• Single 
script 
for 
all 
steps 
• Build 
triggers 
& 
parameters 
like 
regular 
projects 
• Each 
workflow 
execu=on 
is 
a 
regular 
Jenkins 
build 
displayed 
in 
regular 
Jenkins 
views 
• Graphical 
visualiza=on 
of 
actual 
build 
possible 
Not 
of 
visualiza=on 
job 
defini=on 
but 
of 
build 
execu=on 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
27
Non-Sequential Logic 
timeout(time: 300, unit: 'SECONDS') { 
} 
try {} catch {} 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
28
Interaction with Humans 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
29
Restartable Build / Checkpoint 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
30
Visualization 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
31
Stages 
• Semaphore 
• Visualiza=on 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
32
Comprehensible Scripts 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
33
Workflow Syntax Card 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
34
Workflow Syntax Card 
• stage: 
Enter 
a 
new 
stage 
• node: 
Allocate 
node 
• ws: 
Allocate 
workspace 
• parallel: 
Execute 
sub-­‐workflow 
in 
parallel 
• retry: 
Retry 
the 
body 
up 
to 
N 
=mes 
• catchError: 
Catch 
error 
and 
con=nue 
• timeout: 
Execute 
the 
body 
with 
a 
=meout 
• input: 
Input 
/ 
human 
interac=on 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
35
Workflow Syntax Card 
• load: 
Evaluate 
a 
Groovy 
source 
file 
into 
the 
workflow 
script 
• step: 
General 
build 
step 
• sh: 
Shell 
script 
• bat: 
Windows 
batch 
script 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
36
Workflow Syntax Card 
• archive: 
Archive 
ar=facts 
• unarchive: 
Copy 
archived 
ar=fact 
into 
the 
workspace 
• echo: 
Print 
message 
• dir: 
Change 
directory 
• readFile: 
Read 
file 
from 
workspace 
• writeFile: 
Write 
file 
to 
workspace 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
37
Workflow Syntax Card 
• git: 
Git 
• svn: 
Subversion 
• scm: 
General 
SCM 
• tool: 
install 
a 
tool 
• build: 
Build 
a 
job 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
38
Workflow Syntax Card 
• checkpoint: 
capture 
the 
state 
of 
the 
execu=on 
so 
that 
it 
can 
be 
restarted 
later 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
39
Possible Futures 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
40
Possible Futures 
Probably OSS 
• More 
plugin 
interoperability 
• Mul=-­‐branch 
project 
(& 
SCM 
API) 
integra=on 
• More 
advanced 
SCM 
• In-­‐IDE 
edi=ng 
support 
• Concise 
syntax 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
41
Possible Futures 
Probably CloudBees Jenkins Enterprise and Operations Center 
• More 
visualiza=ons 
• Validated 
merge 
integra=on 
• Deployment, 
incl. 
blue/green 
with 
rollback 
• Freestyle 
and/or 
Build 
Flow 
import 
• Templates 
integra=on 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
42
Get The Code 
• hdps://gist.github.com/cyrille-­‐leclerc/0dc73659e6d2a92f014a 
– workflow.groovy 
• hdps://github.com/cyrille-­‐leclerc/spring-­‐petclinic/ 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
43
More Workflow Resources 
• Tutorial 
– hdps://github.com/jenkinsci/workflow-­‐ 
plugin/blob/master/TUTORIAL.md 
• Jenkins 
Enterprise 
by 
CloudBees 
Workflow-­‐related 
Func=onality 
– hdp://jenkins-­‐enterprise.cloudbees.com/ 
docs/user-­‐guide-­‐docs/workflow.html 
• More 
webinars 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
44
Cyrille Le Clerc 
Director, Product Management 
cleclerc@cloudbees.com 
@cyrilleleclerc 
Steve Harris 
SVP, Products 
sharris@cloudbees.com 
@stevengharris 
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
45
©2014 
CloudBees, 
Inc. 
All 
Rights 
Reserved 
46

Jenkins Workflow Webinar - Dec 10, 2014

  • 1.
    Orchestrating the ContinuousDelivery Process in Jenkins with Workflow ©2014 CloudBees, Inc. All Rights Reserved 1
  • 2.
    Today’s Presenters CyrilleLe Clerc Director, Product Management cleclerc@cloudbees.com @cyrilleleclerc Steve Harris SVP, Products sharris@cloudbees.com @stevengharris ©2014 CloudBees, Inc. All Rights Reserved 2
  • 3.
    Using WebEx Questions? Submit via the Q&A window at any time during the presentation. We will cover Q&A at the end of the presentation. Session is being recorded. ©2014 CloudBees, Inc. All Rights Reserved 3
  • 4.
    Agenda • Con=nuous Delivery • Jenkins & Con=nuous Delivery • Workflow in Jenkins Today • The New Jenkins Workflow Engine • Jenkins Workflow Syntax Card • Possible Futures ©2014 CloudBees, Inc. All Rights Reserved 4
  • 5.
    Continuous Delivery ©2014 CloudBees, Inc. All Rights Reserved 5
  • 6.
    Continuous Delivery •“Reliable So+ware Releases through Build, Test, and Deployment Automa=on” • DONE = Shippable into Produc=on ©2014 CloudBees, Inc. All Rights Reserved 6
  • 7.
    Continuous Integration Steps Con$nuous Integra$on Source Code Quality Analysis Compile & Unit Tests Binaries ©2014 CloudBees, Inc. All Rights Reserved 7
  • 8.
    Continuous Delivery Steps Con$nuous Delivery DEV DEV QA OPS Source Code Quality Analysis Compile & Unit Tests Binaries Perfs Environment Func Test Environment UAT Environment Production Environment GO LIVE! Release! Staging Environment 8
  • 9.
    Continuous Delivery Pipeline Continuous Delivery Pipeline Compile & Unit Tests Perfs Tests Selenium Tests Deploy UAT Sonar Analysis Deploy Staging Deploy Production ©2014 CloudBees, Inc. All Rights Reserved 9
  • 10.
    Jenkins: Hub ofContinuous Delivery • Connect the dots • It is the process Source Code Perfs Environment Func Test Environment UAT Environment Binaries Quality Analysis Compile & Unit Tests ©2014 CloudBees, Inc. All Rights Reserved 10
  • 11.
    CI/CD with Jenkinsand Vagrant and Puppet puppet deployment module java code Dev Environment vagrant provision puppet apply war file + puppet manifests & modules petclinic.war Puppet Agent App. Server QA Environment petclinic.war Puppet Agent App. Server Prod Environment petclinic.war Puppet Agent App. Server war file + puppet manifests & modules Puppet Master Puppet Master OPS war file + puppet manifests & modules Jenkins builds war file and Puppet modules and deploys via Vagrant
  • 12.
    CI/CD with Jenkinsand Vagrant and Puppet puppet deployment module java code Dev Environment notification vagrant provision puppet apply war file + puppet manifests & modules petclinic.war Puppet Agent App. Server QA Environment petclinic.war Puppet Agent App. Server Prod Environment petclinic.war Puppet Agent App. Server notification war file + puppet manifests & modules Puppet Master Puppet Master OPS war file + puppet manifests & modules Jenkins builds war file and Puppet modules and deploys via Vagrant
  • 13.
    Jenkins – PuppetIntegration
  • 14.
    CD Pipeline èWorkflow Continuous Delivery Pipeline Compile & Unit Tests Perfs Tests Selenium Tests Deploy UAT Sonar Analysis Deploy Staging Deploy Production ©2014 CloudBees, Inc. All Rights Reserved 14
  • 15.
    What We Need • Complex pipelines involving mul=ple stages • Non-­‐sequen$al logic such as loops, forks … • Long-­‐running builds must survive outages • Interac$ons with humans including pauses, input • Restartable builds in case of transient errors • Reusable defini$ons to avoid duplica=on • Comprehensible scripts with one clear defini=on ©2014 CloudBees, Inc. All Rights Reserved 15
  • 16.
    Most Existing WorkflowIn Jenkins Today • Job Chaining • Build Flow Plugin • Build Pipeline Plugin • Build Delivery Pipeline ©2014 CloudBees, Inc. All Rights Reserved 16
  • 17.
    Most Existing WorkflowIn Jenkins Today • Many atomic jobs • Hard to share variables/state between jobs • Limited logic • Mix build triggers, parameterized build … ©2014 CloudBees, Inc. All Rights Reserved 17
  • 18.
    Jenkins Workflow Engine ©2014 CloudBees, Inc. All Rights Reserved 18
  • 19.
    Simplifying Our SampleWorkflow Compile & Unit Tests Perfs Tests Selenium Tests Deploy UAT Sonar Analysis Deploy Staging Deploy Production ©2014 CloudBees, Inc. All Rights Reserved 19
  • 20.
    Simplifying Our SampleWorkflow Compile & Unit Tests Perfs Tests Selenium Tests Deploy UAT Sonar Analysis Deploy Staging Deploy Production ©2014 CloudBees, Inc. All Rights Reserved 20
  • 21.
    What We Need • Complex pipelines involving mul=ple stages • Non-­‐sequen$al logic such as loops, forks … • Long-­‐running builds must survive outages • Interac$ons with humans including pauses, input • Restartable builds in case of transient errors • Reusable defini$ons to avoid duplica=on • Comprehensible scripts with one clear defini=on ©2014 CloudBees, Inc. All Rights Reserved 21
  • 22.
  • 23.
    Production Release AvailableNOW! • Jenkins OSS – Workflow 1.0 released December 3 • Beta out since May, with great, engaged feedback • Install Workflow: Aggregator in LTS 1.580.x or a later weekly release • Jenkins Enterprise by CloudBees – Automa=cally available as of the 14.11 release ©2014 CloudBees, Inc. All Rights Reserved 23
  • 24.
    Demo Time! ©2014 CloudBees, Inc. All Rights Reserved 24
  • 25.
    Key Features •En=re flow is one concise Groovy script – For loops, try-­‐finally, fork-­‐join … • Can restart Jenkins while flow is running • Allocate slave nodes and workspaces – As many as you want, when you want • Stages throdle concurrency of builds • Human input/approval integrated into flow • Standard project concepts: SCM, ar=facts, plugins ©2014 CloudBees, Inc. All Rights Reserved 25
  • 26.
    Groovy DSL vs.Graphical Workflow • Familiar control flow construc=on • Familiar “tools” for building abstrac=ons Func=ons, classes, variables, … • Workflow in version control • As opposed to: Graphical workflow designer ©2014 CloudBees, Inc. All Rights Reserved 26
  • 27.
    Project Setup •One workflow is defined as a job • Single script for all steps • Build triggers & parameters like regular projects • Each workflow execu=on is a regular Jenkins build displayed in regular Jenkins views • Graphical visualiza=on of actual build possible Not of visualiza=on job defini=on but of build execu=on ©2014 CloudBees, Inc. All Rights Reserved 27
  • 28.
    Non-Sequential Logic timeout(time:300, unit: 'SECONDS') { } try {} catch {} ©2014 CloudBees, Inc. All Rights Reserved 28
  • 29.
    Interaction with Humans ©2014 CloudBees, Inc. All Rights Reserved 29
  • 30.
    Restartable Build /Checkpoint ©2014 CloudBees, Inc. All Rights Reserved 30
  • 31.
    Visualization ©2014 CloudBees, Inc. All Rights Reserved 31
  • 32.
    Stages • Semaphore • Visualiza=on ©2014 CloudBees, Inc. All Rights Reserved 32
  • 33.
    Comprehensible Scripts ©2014 CloudBees, Inc. All Rights Reserved 33
  • 34.
    Workflow Syntax Card ©2014 CloudBees, Inc. All Rights Reserved 34
  • 35.
    Workflow Syntax Card • stage: Enter a new stage • node: Allocate node • ws: Allocate workspace • parallel: Execute sub-­‐workflow in parallel • retry: Retry the body up to N =mes • catchError: Catch error and con=nue • timeout: Execute the body with a =meout • input: Input / human interac=on ©2014 CloudBees, Inc. All Rights Reserved 35
  • 36.
    Workflow Syntax Card • load: Evaluate a Groovy source file into the workflow script • step: General build step • sh: Shell script • bat: Windows batch script ©2014 CloudBees, Inc. All Rights Reserved 36
  • 37.
    Workflow Syntax Card • archive: Archive ar=facts • unarchive: Copy archived ar=fact into the workspace • echo: Print message • dir: Change directory • readFile: Read file from workspace • writeFile: Write file to workspace ©2014 CloudBees, Inc. All Rights Reserved 37
  • 38.
    Workflow Syntax Card • git: Git • svn: Subversion • scm: General SCM • tool: install a tool • build: Build a job ©2014 CloudBees, Inc. All Rights Reserved 38
  • 39.
    Workflow Syntax Card • checkpoint: capture the state of the execu=on so that it can be restarted later ©2014 CloudBees, Inc. All Rights Reserved 39
  • 40.
    Possible Futures ©2014 CloudBees, Inc. All Rights Reserved 40
  • 41.
    Possible Futures ProbablyOSS • More plugin interoperability • Mul=-­‐branch project (& SCM API) integra=on • More advanced SCM • In-­‐IDE edi=ng support • Concise syntax ©2014 CloudBees, Inc. All Rights Reserved 41
  • 42.
    Possible Futures ProbablyCloudBees Jenkins Enterprise and Operations Center • More visualiza=ons • Validated merge integra=on • Deployment, incl. blue/green with rollback • Freestyle and/or Build Flow import • Templates integra=on ©2014 CloudBees, Inc. All Rights Reserved 42
  • 43.
    Get The Code • hdps://gist.github.com/cyrille-­‐leclerc/0dc73659e6d2a92f014a – workflow.groovy • hdps://github.com/cyrille-­‐leclerc/spring-­‐petclinic/ ©2014 CloudBees, Inc. All Rights Reserved 43
  • 44.
    More Workflow Resources • Tutorial – hdps://github.com/jenkinsci/workflow-­‐ plugin/blob/master/TUTORIAL.md • Jenkins Enterprise by CloudBees Workflow-­‐related Func=onality – hdp://jenkins-­‐enterprise.cloudbees.com/ docs/user-­‐guide-­‐docs/workflow.html • More webinars ©2014 CloudBees, Inc. All Rights Reserved 44
  • 45.
    Cyrille Le Clerc Director, Product Management cleclerc@cloudbees.com @cyrilleleclerc Steve Harris SVP, Products sharris@cloudbees.com @stevengharris ©2014 CloudBees, Inc. All Rights Reserved 45
  • 46.
    ©2014 CloudBees, Inc. All Rights Reserved 46