Docker and Jenkins.

Orchestrating Continuous Delivery

alexsotob -

Software is eating the world

Key is Automation

speed + friction = HEAT

GO - GO - GO

Containers Codify
OS Config

How I build a Docker image?

$ docker run -ti ubuntu:12.10 bash

[a2b] apt-get update
[a2b] apt-get install curl
[a2b] exit

$ docker commit -m "curl installed" a2b username/image
$ docker build .

Jenkins: Docker and CD

Build, Test, & Deploy Docker Images from Jenkins

Docker Hub Notification Plugin

Docker Traceability Plugin

Docker Plugin

Docker Custom Build Environment Plugin

Build and Publish Plugin

No More Build Jobs/Up/Downstreams PLEASE!!!!

Pipeline Plugin

Continuous Delivery as Code

Features of Pipeline Plugin

Jenkinsfile (1/3)

stage 'compileAndUnit'
node {
        git branch: 'master', url: ''
        gradle 'clean test'
        stash excludes: 'build/', includes: '**', name: 'source'
        stash includes: 'build/jacoco/*.exec', name: 'unitCodeCoverage'
        step([$class: 'JUnitResultArchiver', testResults: '**/build/test-results/*.xml'])

stage 'codeQuality'
parallel 'pmd' : {
    node {
        unstash 'source'
        gradle 'pmdMain'
        step([$class: 'PmdPublisher', pattern: 'build/reports/pmd/*.xml'])
}, 'jacoco': {
    node {
        unstash 'source'
        unstash 'unitCodeCoverage'
        gradle 'jacocoTestReport'

Jenkinsfile (2/3)

stage 'assemble-binaries'

node('linux') {
    unstash 'source'
    withEnv(["SOURCE_BUILD_NUMBER=${env.BUILD_NUMBER}"]) {
        gradle 'assemble'

input message: "Deploy Application to QA ?"

stage name: 'Deploy to QA', concurrency: 1
node {
    echo "Application Deployed to QA."

Jenkinsfile (3/3)

gradle = load 'jenkins/gradle.groovy'

withCredentials([[$class: 'UsernamePasswordMultiBinding', 
                  credentialsId: 'MyID', usernameVariable: 'GIT_USERNAME', 
                  passwordVariable: 'GIT_PASSWORD']]) {
sh "git tag -a some_tag -m 'Jenkins'"
  sh "git push https://${env.GIT_USERNAME}:${env.GIT_PASSWORD}@ --tags"

def mvnHome tool 'Maven 3.3.3'
sh "${mvnHome}/bin/mvn -B verify"

Docker Pipeline Integration

Jenkinsfile (1/2)

docker.withRegistry('', 'd4fc3fa9-39f7-47ea-a57c-795642f90989') {
    git '' 
    def newApp = "${env.BUILD_TAG}"

docker.image('lordofthejars/javatest').withRun {c ->
  sh './'

Jenkinsfile (2/2)

docker.image('maven:3.3.3-jdk-8').inside('-v ~/.m2/repository:/m2repo -u 1000:50') {
  git '…your-sources…'
  sh 'mvn -Dmaven.repo.local=/m2repo clean install'

docker.withServer('tcp://', 'swarm-certs') {
  docker.image('httpd').withRun('-p 8080:80') {c ->
    sh "curl -i http://${hostIp(c)}:8080/"
def hostIp(container) {
  sh "docker inspect -f {{.Node.Ip}} ${} > hostIp"

Different Ways of Doing Same Things with DSL

Simple Build for Pipeline Plugin


simpleBuild {
  machine = "hi-speed"
  docker = "java:1.9"
  env = [
    FOO : 42,
    BAR : "YASS"
  git_repo = ""
  before_script = "echo before"
  script = 'echo after $FOO'
  after_script = 'echo done now'
  notifications = [
    email : ""

Let's wind


Only One Piece of the Jigsaw

Follow the Rules, Adapt to your Needs



It is not necessary to change.
Survival is not mandatory.

W. Edwards Deming