DevOops 2019 - Under the hood of serverless Jenkins. Jenkinsfile Runner

DevOops 2019 - Under the hood of serverless Jenkins. Jenkinsfile Runner

There were significant changes in the Jenkins project over last year. It is still one of the most popular automation servers in the world, but it is not just a "server" anymore. In 2019 Jenkins is a universal automation engine, which actively evolves towards the new Cloud Native architecture and which can be used in any CI/CD flows. It can be used not only as a server, but also as a FaaS. And it is not only about Jenkins X in Kubernetes, but also about more classic usages.

In this talk Oleg will present Jenkinsfile Runner — an engine which allows running Jenkins Pipelines in a single-shot container in any environment. Running Jenkins pipelines in Travis? Easy. In FaaS like AWS Lambda? We can do it as well. Speaker will show examples for these services few other use-cases (Jenkins X, CodeShip, Tekton). And, finally, he will show how to package your own Jenkinsfile Runner images with several plug-ins and preconfiguration.

568e3391c8b528f2b255443e4cca27ca?s=128

Oleg Nenashev

October 30, 2019
Tweet

Transcript

  1. © 2019 CloudBees, Inc. All Rights Reserved. Under the hood

    of serverless Jenkins Jenkinsfile Runner Oleg Nenashev (@oleg_nenashev) CloudBees, Inc. St. Petersburg, Oct 30, 2019
  2. © 2019 CloudBees, Inc. All Rights Reserved. TL;DR “You can

    run Jenkins Pipelines as single-shot container in any environment” 2 This talk: How to do it?
  3. © 2019 CloudBees, Inc. All Rights Reserved. > whoami 3

    @oleg_nenashev oleg-nenashev • Based in Neuchatel, Switzerland • Principal SW Engineer, CloudBees • Jenkins core maintainer
  4. © 2019 CloudBees, Inc. All Rights Reserved. > whoami -jenkins

    4 @oleg_nenashev oleg-nenashev
  5. © 2019 CloudBees, Inc. All Rights Reserved. • CloudBees Jenkins

    Distribution • CloudBees Jenkins Support • Community, e.g. Java 11 support, Jenkinsfile Runner, JCasC > whoami -cloudbees 5 https://www.cloudbees.com
  6. © 2019 CloudBees, Inc. All Rights Reserved. About you 6

    Disclaimer: Opinions are mine; typos are mine
  7. © 2019 CloudBees, Inc. All Rights Reserved. • Automation server/framework

    • Open-source • More than 1700 plugins • Big community • Commercial support is available Who is Mr. Jenkins? 7
  8. © 2019 CloudBees, Inc. All Rights Reserved. Hudson/Jenkins as you

    knew it… in 2011 Batteries are not included Complex configuration Mega-masters, limited scalability Painful upgrades Maintenance is required 8
  9. © 2019 CloudBees, Inc. All Rights Reserved. • Pipeline-as-Code •

    Configuration-as-Code • New plugins and integrations • Modern packaging • Jenkins X Jenkins in 2019 9
  10. © 2019 CloudBees, Inc. All Rights Reserved. 10 Permanent agents

    On-demand agents from cloud providers Jenkins Master Web UI
  11. © 2019 CloudBees, Inc. All Rights Reserved. Master as a

    SPoF Macroservice 11 Permanent agents On-demand agents from cloud providers Web UI Jenkins Master
  12. © 2019 CloudBees, Inc. All Rights Reserved. Aug 31, 2018

    – Kohsuke Kawaguchi, “Jenkins: Shifting Gears” https://jenkins.io/blog/2018/08/31/shifting-gears/ 12
  13. © 2019 CloudBees, Inc. All Rights Reserved. Shifting Gears: Making

    Changes 13
  14. © 2019 CloudBees, Inc. All Rights Reserved. “General purpose CI/CD

    engine that runs on Kubernetes and embraces fundamentally different architecture & extensibility mechanisms” Cloud Native Jenkins 14 https://flic.kr/p/75ncBF Kohsuke Kawaguchi, 2018
  15. © 2019 CloudBees, Inc. All Rights Reserved. • Best service

    for each need • Pay per use • “Infinite” scaling • Easy to use • Easy to maintain • Fast to develop Cloud Native Jenkins 15 https://flic.kr/p/75ncBF
  16. © 2019 CloudBees, Inc. All Rights Reserved. Founded in July

    2018 https://jenkins.io/sigs/cloud-native Goal: Improve Jenkins to run on cloud environments as a "Cloud Native" application Cloud Native Special Interest Group 16 ?
  17. © 2019 CloudBees, Inc. All Rights Reserved. Jenkins X? 17

  18. © 2019 CloudBees, Inc. All Rights Reserved. 18 https://jenkins-x.io

  19. © 2019 CloudBees, Inc. All Rights Reserved. 19

  20. © 2019 CloudBees, Inc. All Rights Reserved. 20 • AWESOME

    (c) Jenkins X 2.x is…
  21. © 2019 CloudBees, Inc. All Rights Reserved. 21 • AWESOME

    (c) • Cloud native • K8s native • Scalable • Designed for CD • Moving fast Jenkins X 2.x is…
  22. © 2019 CloudBees, Inc. All Rights Reserved. 22 • AWESOME

    (c) • Cloud native • K8s native • Scalable • Designed for CD • Moving fast • Kubernetes-only • GitOps-only • Limited SCMs support • Limited CI capabilities • No auto-migration from Jenkins Jenkins X 2.x is… Limitations
  23. © 2019 CloudBees, Inc. All Rights Reserved. 23 • AWESOME

    (c) • Cloud native • K8s native • Scalable • Designed for CD • Moving fast • Kubernetes-only • GitOps-only • Limited SCMs support • Limited CI capabilities Jenkins X 2.x is… Limitations Try out Jenkins X if it fits your environment OR if you plan to go all-in Kubernetes. Jenkins is still around for other cases
  24. © 2019 CloudBees, Inc. All Rights Reserved. Going Back? 24

  25. © 2019 CloudBees, Inc. All Rights Reserved. Master as a

    SPoF Macroservice 25 Permanent agents On-demand agents from cloud providers Web UI Jenkins Master
  26. © 2019 CloudBees, Inc. All Rights Reserved. (┛ಠ_ಠ)┛彡┻━┻ What if

    Jenkins master was “on-demand”?
  27. © 2019 CloudBees, Inc. All Rights Reserved. 27

  28. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfile Runner https://github.com/jenkinsci/jenkinsfile-runner

    Started by Kohsuke in Mar 2018 30 contributors Status: Beta (1.0-beta-11) 28
  29. © 2019 CloudBees, Inc. All Rights Reserved. JFR TL;DR •

    Runs Pipeline and shuts down • Fat JAR or a thin JAR pack • Docker image • Runs everywhere • Startup in milliseconds/seconds 29 https://github.com/jenkinsci/jenkinsfile-runner
  30. © 2019 CloudBees, Inc. All Rights Reserved. 30 STDOUT/STDERR Workspace

    External storage Workspace Jenkinsfile Configuration (WAR, plugins, settings)
  31. © 2019 CloudBees, Inc. All Rights Reserved. Usage: jenkinsfile-runner [options]

    [params] Options: -f (--file) FILE : Path to Jenkinsfile (or directory containing a Jenkinsfile) to run -w (--jenkins-war) FILE : Path to the exploded jenkins.war directory -p (--plugins) FILE : plugins.txt file or a /plugins installation directory Advanced: --runHome FILE : Path to the empty Jenkins Home directory to use for this run --runWorkspace FILE : Path to the workspace to be used within node{} context. -a (--arg) : Parameters to be passed to workflow job -b (--build-number) N : Build number of the run -c (--cause) VAL : Cause of the run -n (--job-name) VAL : Name of the job the run belongs to -ns (--no-sandbox) : Disable the sandbox environment 31
  32. © 2019 CloudBees, Inc. All Rights Reserved. Usage in Docker

    32 docker run --rm \ -v $(pwd)/Jenkinsfile:/workspace/Jenkinsfile \ jenkins4eval/jenkinsfile-runner* * or another image….
  33. © 2019 CloudBees, Inc. All Rights Reserved. Demo. Our Jenkinsfile

    33
  34. © 2019 CloudBees, Inc. All Rights Reserved. 34

  35. © 2019 CloudBees, Inc. All Rights Reserved. 35

  36. © 2019 CloudBees, Inc. All Rights Reserved. • Not a

    CI/CD solution on its own Limitations 36 Triggers Webhook receivers Log services Result Storage Web UI
  37. © 2019 CloudBees, Inc. All Rights Reserved. • Not a

    CI/CD solution on its own • Jenkinsfile Runner is not 100% Jenkins • No Web UI • No build throttling, cross-master communication, etc. • Designed for a single-container • Slow agent connection • No out-of-the-box sidecar containers support Limitations 37
  38. © 2019 CloudBees, Inc. All Rights Reserved. But 38 Triggers

    Webhook receivers Log services Result Storage Web UI
  39. © 2019 CloudBees, Inc. All Rights Reserved. But 39 Triggers

    Webhook receivers Log services Result Storage Web UI
  40. © 2019 CloudBees, Inc. All Rights Reserved. “Packaging”? 40

  41. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfile Runner flavors

    41 Vanilla: Docker/Binary in the official repo • Basic plugins: Pipeline, JCasC, etc. • GitHub: jenkinsci/jenkinsfile-runner • DockerHub: jenkins4eval/jenkinsfile-runner
  42. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfile Runner flavors

    42 Custom JFR packages • Way to go in 95% of cases • Ready-to-fly Docker images with plugins and configs • Extending the Vanilla Docker image • https://jenkins.io/blog/2018/10/16/custom-war-packager/ Vanilla: Docker/Binary in the official repo • Basic plugins: Pipeline, JCasC, etc. • GitHub: jenkinsci/jenkinsfile-runner • DockerHub: jenkins4eval/jenkinsfile-runner
  43. © 2019 CloudBees, Inc. All Rights Reserved. Building custom Jenkinsfile

    Runner images 43 https://jenkins.io/blog/2018/10/16/custom-war-packager/ Custom WAR Packager Jenkinsfile Runner Core and Plugins Configuration-as-code Packaging Ready-to-fly Docker image Base image Y A M L
  44. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfile Runner. Usage

    examples Jenkins X 1.x, serverless mode • jenkins-x/jenkins-x-serverless ci.jenkins.io-runner • jenkinsci/ci.jenkins.io-runner “FaaS” packaging • GitHub Actions: jonico/jenkinsfile-runner-github-actions • Codeship: oleg-nenashev/codeship-jenkinsfile • AWS Lambda: carlossg/jenkinsfile-runner-lambda • Project Fn: carlossg/jenkinsfile-runner-fn 44
  45. © 2019 CloudBees, Inc. All Rights Reserved. Jenkins X 1.0

    Serverless Engine example 45
  46. © 2019 CloudBees, Inc. All Rights Reserved. Jenkins X. Serverless

    Mode (before April 2019) 46 https://medium.com/@jdrawlings/ser verless-jenkins-with-jenkins-x- 9134cbfe6870 Serverless Jenkins with Jenkins X
  47. © 2019 CloudBees, Inc. All Rights Reserved. Jenkins X 2.x.

    Modes and engines 47 Static Masters Serverless build engines Jenkinsfile Runner Tekton (default in 2.0) Classic Jenkins @Deprecated
  48. © 2019 CloudBees, Inc. All Rights Reserved. Jenkins X 1.x.

    Serverless Mode packaging 48 Single-shot masters build flow
  49. 49

  50. 50 Jenkinsfile Runner Jenkinsfile Runner is Here

  51. © 2019 CloudBees, Inc. All Rights Reserved. CommentOps - communication

    with users 51
  52. © 2019 CloudBees, Inc. All Rights Reserved. GitHub Actions …

    and Jenkinsfile Runner 52
  53. © 2019 CloudBees, Inc. All Rights Reserved. https://github.com/features/actions 53

  54. © 2019 CloudBees, Inc. All Rights Reserved. GitHub Actions! 54

    https://github.com/jonico/jenkinsfile-runner-github-actions
  55. © 2019 CloudBees, Inc. All Rights Reserved. Sample definition 55

  56. © 2019 CloudBees, Inc. All Rights Reserved. 56

  57. © 2019 CloudBees, Inc. All Rights Reserved. 57

  58. © 2019 CloudBees, Inc. All Rights Reserved. GitHub Actions is

    in Limited Beta GA - November 13! 58
  59. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfiles on CodeShip?

  60. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfile Runner on

    CloudBees CodeShip • Jenkins has no good SaaS (now) • CodeShip Pro - CI SaaS with native Docker support • Free tiers for open-source projects • What if we run Jenkins there? 60 https://codeship.com/features/pro
  61. © 2019 CloudBees, Inc. All Rights Reserved. Demo 1 61

    codeship-steps.yml codeship-services.yml Jenkinsfile https://github.com/oleg-nenashev/codeship-jenkinsfile
  62. © 2019 CloudBees, Inc. All Rights Reserved. 62

  63. © 2019 CloudBees, Inc. All Rights Reserved. Example 2. Building

    a Jenkins plugin in CodeShip https://github.com/oleg-nenashev/mailer-plugin/tree/codeship-demo • Using ci.jenkins.io-runner ◦ https://github.com/jenkinsci/ci.jenkins.io-runner • Using the standard Jenkins Pipeline library ◦ https://github.com/jenkins-infra/pipeline-library • Using standard Jenkinsfile ◦ buildPlugin() 63
  64. © 2019 CloudBees, Inc. All Rights Reserved. Example 2. Building

    a Jenkins plugin in CodeShip 64 codeship-services.yml codeship-steps.yml Jenkinsfile
  65. © 2019 CloudBees, Inc. All Rights Reserved. 65

  66. © 2019 CloudBees, Inc. All Rights Reserved. CodeShip. Build history

    66
  67. © 2019 CloudBees, Inc. All Rights Reserved. • Jenkins X

    • GitHub Actions • CloudBees CodeShip We talked about… 67
  68. © 2019 CloudBees, Inc. All Rights Reserved. Last but not

    least? 68
  69. © 2019 CloudBees, Inc. All Rights Reserved. Jenkins 69

  70. © 2019 CloudBees, Inc. All Rights Reserved. Running JFR from

    Jenkins Well, “docker run”… 70
  71. © 2019 CloudBees, Inc. All Rights Reserved. 71

  72. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfile Runner Test

    Framework https://github.com/jenkinsci/jenkinsfile-runner-test-framework • Custom WAR Packager • Docker • shUnit2 72
  73. © 2019 CloudBees, Inc. All Rights Reserved. If Pipeline Unit

    is not enough… https://github.com/jenkinsci/JenkinsPipelineUnit Works for Mock Unit tests JFR Test framework for integration tests 73
  74. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfile Runner Test

    Framework Jenkinsfile Runner packages Jenkinsfiles Pipeline libraries 74 Tests
  75. © 2019 CloudBees, Inc. All Rights Reserved. • Waiting for

    user feedback/patches • TBD - Jenkinsfile Runner 1.0 • Packaging for common cases • Lightweight sidecar containers • Jenkinsfile Runner Jenkins Plugin? • Experiments with GraalVM and Quarkus Future work 75
  76. © 2019 CloudBees, Inc. All Rights Reserved. 76 !=

  77. © 2019 CloudBees, Inc. All Rights Reserved. • Jenkins-as-a-function is

    real • You can run your Pipelines everywhere • There are tools for that • Use Jenkins X if applicable (K8s/GitOps) • Consider Jenkinsfile Runner if not Takeaways 77
  78. © 2019 CloudBees, Inc. All Rights Reserved. • jenkinsci/jenkinsfile-runner •

    CONTRIBUTING.md in the repository • 1 day of Hacktoberfest left ;) ◦ https://jenkins.io/events/hacktoberfest/ It is a great time to contribute! 78
  79. © 2019 CloudBees, Inc. All Rights Reserved. Contacts: E-mail: onenashev@cloudbees.com

    GitHub: oleg-nenashev Twitter: @oleg_nenashev QUESTIONS?