48
Jenkins, Pipeline, and Docker Mile High Agile 2017 Mark Waite Twitter: @MarkEWaite E-mail: [email protected]

Jenkins, pipeline and docker

Embed Size (px)

Citation preview

Page 1: Jenkins, pipeline and docker

Jenkins, Pipeline, and DockerMile High Agile 2017Mark WaiteTwitter: @MarkEWaiteE-mail: [email protected]

Page 2: Jenkins, pipeline and docker

Introduction

Page 3: Jenkins, pipeline and docker

Introduction

• I’m Mark Waite

– Technical Evangelist at CloudBees

– Previously at CA Technologies, PTC, CoCreate, & HP

• Builds, tools, and rapid feedback for a long time

• I maintain the Jenkins git plugin

Page 4: Jenkins, pipeline and docker

Continuous Delivery

Page 5: Jenkins, pipeline and docker

Jenkins Pipeline

Page 6: Jenkins, pipeline and docker

Jenkins Pipeline

• Pipeline as Code

– Capture the entire continuous delivery process

– Check a Jenkinsfile into your source repo

• jenkins.io/doc/book/pipeline

Page 7: Jenkins, pipeline and docker

Blue Ocean

Page 8: Jenkins, pipeline and docker
Page 9: Jenkins, pipeline and docker
Page 10: Jenkins, pipeline and docker
Page 11: Jenkins, pipeline and docker

Blue Ocean

docker run -p 8080:8080 -u root \-v /var/run/docker.sock:/var/run/docker.sock \jenkinsci/blueocean

Page 12: Jenkins, pipeline and docker
Page 13: Jenkins, pipeline and docker

Zero

Page 14: Jenkins, pipeline and docker

A basic Java application

• MarkEWaite/jhipster-sample-app

• Tools

– Maven

– Node / Gulp

– Gatling

– Docker

Page 15: Jenkins, pipeline and docker

Planning the pipeline

Page 16: Jenkins, pipeline and docker

Planning the pipeline

• Stages desired:

– Build

– Test

o Unit

o Performance

o Front-end

– Static Analysis

– Deployment

Page 17: Jenkins, pipeline and docker
Page 18: Jenkins, pipeline and docker
Page 19: Jenkins, pipeline and docker

Planning the pipeline

• Stages desired:

– Build

– Test

o Unit

o Performance

o Front-end

– Static Analysis

– Deployment

Page 20: Jenkins, pipeline and docker

Build

Page 21: Jenkins, pipeline and docker

Build

• Don't reinvent your build system in Jenkins Pipeline

– Think of Pipeline as glue

• Goal:

– Perform a reproducible build

– Create an artifact which can used later

o To run tests against

o To deploy to an environment

• In this case, we're using Maven.

Page 22: Jenkins, pipeline and docker

Build

pipeline {agent anystages {stage('Build') {

steps {sh 'mvn'

}}

}}

Page 23: Jenkins, pipeline and docker

Build

stage('Build') {agent {docker {

image 'maven:3-alpine'args '-v /root/.m2:/root/.m2'

}}/* .. */

}

Page 24: Jenkins, pipeline and docker

Build

stage('Build') {/* .. */steps {sh './mvnw -B clean package'stash name: 'war', includes: 'target'

}}

Page 25: Jenkins, pipeline and docker

Test

Page 26: Jenkins, pipeline and docker

Test

pipeline {agent anystages {stage('Backend Unit Test') {

steps {sh './mvnw -B test'

}}

}}

Page 27: Jenkins, pipeline and docker

Test

stage('Backend Unit Test') {agent {docker {

image 'maven:3-alpine'args '-v /root/.m2:/root/.m2'

}}/* .. */

}

Page 28: Jenkins, pipeline and docker

Test

stage('Backend Unit Test') {/* .. */steps {unstash 'war'sh './mvnw -B test'junit '**/surefire-reports/**/*.xml'

}}

Page 29: Jenkins, pipeline and docker

Test

stage('Backend Performance Test') {/* .. */steps {unstash 'war'sh './mvnw -B gatling:execute'

}}

Page 30: Jenkins, pipeline and docker

Test

stage('Backend') {steps {parallel('Unit' : {unstash 'war'sh './mvnw -B test'junit '**/surefire-reports/**/*.xml'},'Performance' : {unstash 'war'sh './mvnw -B gatling:execute'

})}

}}

Page 31: Jenkins, pipeline and docker

Test

stage('Frontend Test') {agent { docker 'node:alpine' }steps {sh 'yarn install'sh 'yarn global add gulp-cli'sh 'gulp test'

}}

Page 32: Jenkins, pipeline and docker

Analyze

Page 33: Jenkins, pipeline and docker

Build

pipeline {agent anystages {

stage('Analyze') {}

}}

Page 34: Jenkins, pipeline and docker

Analyze

• Static analysis

• Code coverage checks

• Quality scanning

– FindBugs

– PMD

– etc

jenkins.io/blog/2017/04/18/continuousdelivery-devops-

sonarqube/

Page 35: Jenkins, pipeline and docker

Deploy

Page 36: Jenkins, pipeline and docker

Deploy

• Don't reinvent your deployment system in Jenkins

PIpeline

– Think of Pipeline as glue

• "Deployment" may have different meanings

– Deploying to AWS/Azure

– Deploying to a physical datacenter

– Uploading to an app store

– Uploading to an internal artifact server

Page 37: Jenkins, pipeline and docker

Deploy

pipeline {agent anystages {stage('Deploy') {}

}}

Page 38: Jenkins, pipeline and docker

Deploy

stage('Deploy') {steps {sh './deploy.sh'

}}

Page 39: Jenkins, pipeline and docker

Build

Page 40: Jenkins, pipeline and docker

Test

Page 41: Jenkins, pipeline and docker

Deploy

Page 42: Jenkins, pipeline and docker

Other considerations

Page 43: Jenkins, pipeline and docker

Notifications

• Feedback to the team is a key part of continuous delivery

• Jenkins Pipeline can be used for:

– Sending email

– Sending messages to:

o HipChat

o Slack

– Updating JIRA tickets

jenkins.io/node/tags/notifications/

Page 44: Jenkins, pipeline and docker

Manual Promotion

stage('Deploy') {steps {input message: 'Deploy to production?',

ok: 'Fire zee missiles!'

sh './deploy.sh'}

}

Page 45: Jenkins, pipeline and docker

Manual Promotion

Page 46: Jenkins, pipeline and docker

Zero to Continuous Deliverywith Jenkins Pipeline

and Blue Ocean

Page 47: Jenkins, pipeline and docker

Questions?

Page 48: Jenkins, pipeline and docker

Resources

• jenkins.io/doc/book/pipeline

• jenkins.io/projects/blueocean

• Docker containers

– jenkinsci/jenkins:lts-alpine

– jenkinsci/blueocean

[email protected]