Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Continuous Delivery - Pipeline as-code

673 views

Published on

Talk about Continuous Delivery and Jenkins 2 that enables us to define our pipelines with our code. Showing example pipelines, snippets and the new Blue Ocean GUI.

Published in: Technology
  • Be the first to comment

Continuous Delivery - Pipeline as-code

  1. 1. Continuous Delivery Pipeline as code
  2. 2. Mike van Vendeloo Software Craftsman at JPoint TU Delft - Computer Science Scrum master Assignments at customers like KLM, Rabobank, Government, de Persgroep. Focus on improvement of software development process and quality Hobb: Korfball, domotica @mikevanvendeloo
  3. 3. Agenda • Definitions CI/CD/Pipeline • Jenkins 2: Pipeline as code • Pipeline snippets • Reuse with pipeline libraries • Declarative pipelines • Blue Ocean • Demo
  4. 4. Definitions
  5. 5. Definitions - Continuous Integration “Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible.“ Martin Fowler
  6. 6. Continuous Delivery: Automate everything “If it hurts, do it more frequently, and bring the pain forward.” ― Jez Humble, Continuous Delivery
  7. 7. Definitions - Continuous Delivery “Continuous Delivery is the ability to get changes of all types—including new features, configuration changes, bug fixes and experiments—into production, or into the hands of users, safely and quickly in a sustainable way.”
  8. 8. Definitions - Continuous Deployment
  9. 9. Definitions - Pipeline A pipeline is a set of stages to bring functionality from developer to the end user.
  10. 10. Jenkins pipeline as code
  11. 11. Jenkins 1
  12. 12. Jenkins 2 - Pipeline as code
  13. 13. Sample basic pipeline stages ➔ Checkout Source code checkout from repository ➔ Build Compile & Unit test ➔ QA Code style check & integration testing ➔ Deploy Deploy to a server
  14. 14. Basic pipeline definition #!/usr/bin/groovy node('linux') { stage('Checkout') { checkout scm } stage('Build') { sh "mvn clean deploy" junit allowEmptyResults: true, testResults: 'target/surefire-reports/*.xml' } stage('Deploy') { build "Deployer" } }
  15. 15. Pipeline snippets
  16. 16. Error handling node { stage('Doing my thing') { try { sh 'exit 1' } catch (someException) { echo 'Something failed, somebody should be notified!' throw someException } finally { hipchatSend color: 'BLUE', credentialId: 'hipChat', message: “Build result ${env.BUILD_RESULT}”, room: 'BuildResults' } } }
  17. 17. Pipeline properties - cleanup properties( [buildDiscarder( logRotator( artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '7', numToKeepStr: '25') ), pipelineTriggers([]) ] )
  18. 18. Pipeline properties - Parameters properties( [parameters( [choice( choices: ['dev', 'test', 'acc', 'prod'], description: 'Kies de omgeving', name: 'omgeving')] ), pipelineTriggers([]) ])
  19. 19. Parallel tasks parallel ‘test’: { sh ‘mvn clean test’ }, ‘mutation-test’: { Sh ‘mvn org.pitest:pitest-maven:mutationCoverage’ }, failFast: true
  20. 20. Share information between nodes/executors node { stage(‘Build’) sh(“mvn -B clean package”) stash excludes:’target/’, includes: ‘**’, name: ‘source’ } stage (‘test’) { unstash ‘source’ } }
  21. 21. Notifications def notify(String colorCode, String color, String summary) slackSend (color: colorCode, message: summary) hipchatSend (color: color, notify: true, message: summary) emailext ( to: team@mydomain.com', subject: “Build ${env.JOB_NAME} [${env.BUILD_NUMBER}] result ${currentBuild.result}” body: “<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>”, recipientProviders: [[$class: 'DevelopersRecipientProvider']] ) }
  22. 22. Pipeline libraries
  23. 23. Reuse between pipelines: libraries
  24. 24. Library implementation package vanvendeloo.jenkins def checkout(String repositoryName) { git “git@bitbucket.org:vanvendeloo/${repositoryName}” } def updateVersion() { sh “mvn build-helper:parse-version versions:set - DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${ parsedVersion.nextIncrementalVersion} versions:commit” } // Return the contents of this script as object so it can be re-used in Jenkinsfiles. return this
  25. 25. Use the library: @Library @Library(‘pipeline-library’) node { pipelineSteps = new PipelineSteps() stage(‘Preparation’) { pipelineSteps.checkout(‘my-service’) pipelineSteps.updateVersion() } }
  26. 26. Catch: Groovy Sandbox org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: ↵ Scripts not permitted to use method java.lang.String replaceAll java.lang.String java.lang.String 1. Go to Manage Jenkins > In-process Script Approval 2. Review the pending signatures and click Approve to add them to the whitelist 3. Re-run your job; it should no longer fail (for this particular method call)
  27. 27. Declarative pipelines
  28. 28. Declarative Pipelines node { stage(‘Checkout’) { checkout scm } stage(‘Build’) { withEnv(["PATH+MAVEN=${tool 'M3'}/bin"]) { try { sh 'mvn clean install' } catch (e) { currentBuild.result = 'FAILURE' } } } pipeline { agent any tools { maven 'M3' } stages { stage('Checkout') { steps { checkout scm } } stage(Build) { steps { sh ‘mvn clean install’ } post { success { junit '**/surefire-reports/**/*.xml' } } } }
  29. 29. Blue Ocean
  30. 30. Blue Ocean
  31. 31. Pipeline result
  32. 32. Conclusions Pipeline evaluates with your code Reuse in libraries keeps your Jenkinsfile clean and simple BlueOcean definately an improvement, but need to get used to it Pipeline editor very cool feature!
  33. 33. http://github.com/mikevanvendeloo https://jenkins.io/doc/book/pipeline/syntax/ https://jenkins.io/blog/2017/02/07/declarative-maven-project/ Resources
  34. 34. @mikevanvendeloo

×