Top Banner
© 2016 CloudBees, Inc. All Rights Reserved © 2016 CloudBees, Inc. All Rights Reserved
36

Pipeline: Continuous Delivery as Code in Jenkins 2.0

Apr 16, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

©2016CloudBees,Inc.AllRightsReserved

Page 2: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

©2016CloudBees,Inc.AllRightsReserved

Continuous Delivery as Code

Pipeline and Jenkins 2

Page 3: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Continuous Delivery

Continuous delivery (CD) is a software engineering approach in which teams produce software in short cycles, ensuring that the software can be reliably released at any time. It aims at building, testing, and releasing software faster and more frequently. The approach helps reduce the cost, time, and risk of delivering changes by allowing for more incremental updates to applications in production. A straightforward and repeatable deployment process is important for continuous delivery.

https://en.wikipedia.org/wiki/Continuous_delivery

Page 4: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Meet Jenkins 2

jenkins.io/2.0

Page 5: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Jenkins 2 Themes

Pipeline as code: front and center

Improved “out of the box” user experience

User interface improvements

Page 6: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Jenkins 2 Themes

Pipeline as code: front and center

Improved “out of the box” user experience

User interface improvements

Page 7: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Pipeline as code

• Introduce “Pipeline” as a new type in Jenkins • Codify an implicit series of stages into an explicit

pipeline definition (Jenkinsfile) in source control • Resumability/durability of pipeline state • Extend the DSL to meet organizational needs

Page 8: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Creating a Pipeline

Page 9: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Creating a Pipeline

Page 10: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Creating a Pipeline

Page 11: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Creating a Pipeline

Page 12: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Jenkinsfile

node('java8'){

stage('Checkout'){

checkoutscm

}

stage('Build'){

sh'mvncleaninstall'

}

stage('Test'){

sh'mvntest'

}

archiveArtifactsartifacts:'target/**/*.jar',fingerprint:true

}

Page 13: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Pipeline Documentation

jenkins.io/doc

Page 14: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Pipeline Documentation

Page 15: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Snippet Generator localhost:8080/job/niagara/pipeline-syntax

Page 16: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Snippet Generator localhost:8080/job/niagara/pipeline-syntax

Page 17: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

DSL Reference localhost:8080/job/niagara/pipeline-syntax/html

Page 18: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Pipeline Plugins

Extending Pipeline

Page 19: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Pipeline Stage View plugin

Page 20: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Pipeline Multibranch plugin

• Represent pipelines for multiple branches in one "Folder" • Automatically scan a repository for each branch which contains a Jenkinsfile

Page 21: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

GitHub Organization Folder plugin

Page 22: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Blue Ocean jenkins.io/projects/blueocean

Page 23: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Docker Pipeline plugindefimageName='jenkinsciinfra/bind'node('docker'){ checkoutscm

//Computeauniqueimagetag defimageTag="build-${env.BUILD_NUMBER}"

//The`docker`variableintroducedbytheplugin stage('Build'){ defwhale=docker.build("${imageName}:${imageTag}")

}

//PublishthisimagetoDockerHub stage('Deploy'){ whale.push()

}}

Page 24: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Docker Pipeline pluginnode('docker'){

//The`docker`variableintroducedbytheplugin.////InvokingourGradlebuildinsideafreshlyspunup//DockercontainerwithJDK8docker.image('openjdk:8-jdk').inside{ checkoutscm sh'./gradlew--info' archiveArtifactsartifacts:'build/libs/**/*.jar',fingerprint:true}

}

Page 25: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Integration with existing plugins

Pipeline + ??? = Profit.

Page 26: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Plugins that support Pipeline

• A few plugins which provide custom steps for Pipeline scripts: – Tooling: Credentials binding, SSH Agent, Parallel Test – Reporters: JUnit, Brakeman, HTML Publisher, Cucumber Test Result – Notifiers: Slack, HipChat, email-ext – Wrappers: Timestamper

• Plugins work within Pipelines – SCM: Git, SVN, Mercurial, P4, CVS – Wrappers: Ansi Color, NodeJS – Build steps: Ant, etc

• More defined in COMPATIBILITY.md

Page 27: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Steps added by pluginsnode{

/*otherworkhappeneduphere*/

timestamps{

sh'mvncleanpackage'

junit'**/target/surefire-reports/*.xml'

}

if(env.BRANCH_NAME=='master'){

sshagent(credentials:['my-credential-id']){

sh'./run-ssh-deploy-script'

}

}

}

Page 28: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Build Steps

Page 29: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Build Wrappers

github.com/jenkinsci/pipeline-examples

Page 30: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Abstracting Pipeline

Sharing code, best practices and templates for success

Page 31: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Pipeline Shared Libraries

//Thecall()methodinanyfileinpipeline-library.git/varsisexposedasa //methodwiththesamenameasthefile.defcall(defmavenOptions){

docker.image('maven').inside{ timestamps{

sh"mvncleaninstall-Dmaven.test.failure.ignore=true${mavenOptions}"

}junit'**/target/surefire-reports/**/*.xml'

}}

runMaven.groovy

github.com/jenkinsci/pipeline-examples

Page 32: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

node{ checkoutscm stage('Build'){

//LoadsrunMavenstepfromtheSharedLibraryandinvokesit. runMaven } stage('AcceptanceTests'){ git'git://git.example.com/selenium-tests.git' sh'./run-selenium.sh' } stage('Deploy'){ sh'./deploy.sh' }}

Pipeline Shared LibrariesJenkinsfile

github.com/jenkinsci/pipeline-examples

Page 33: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

load step

//Methodsinthisfilewillendupasobjectmethodsontheobjectthatloadreturns.deflookAtThis(StringwhoAreYou){echo"Lookatthis,${whoAreYou}!Youloadedsomethingfromanotherfile!"}

externalMethod.groovy

github.com/jenkinsci/pipeline-examples

//Ifthere'sacallmethod,youcanjustloadthefile,say,as"foo",andtheninvokethatcallmethodwithfoo(...)defcall(StringwhoAreYou){echo"${whoAreYou},saythankstothecall(...)method."}

externalCall.groovy

node{//Loadthefilefromthecurrentdirectory,//intoavariablecalled"externalMethod"defexternalMethod=load("externalMethod.groovy")//CallthemethodwedefinedexternalMethod.lookAtThis("Steve")//Nowload'externalCall.groovy'.defexternalCall=load("externalCall.groovy")//Wecanjustrunitwith`externalCall() ̀externalCall("Steve")}

Jenkinsfile

Page 34: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

Continuous Delivery as Code

Final Thoughts

Page 35: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

• A new pipeline “type” has been introduced • Previously implicit pipelines, chained jobs, can now be

made explicit and committed to SCM • Pipelines have state associated with them and can be

resumed • It’s code. It can be modified and extended

Final Thoughts

Page 36: Pipeline: Continuous Delivery as Code in Jenkins 2.0

©2016Clou

dBees,Inc.A

llRightsReserved

©2016CloudBees,Inc.AllRightsReserved

Questions/Answers

jenkins.io/2.0 jenkins.io/doc @jenkinsci