Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DevOops 2019 - Under the hood of serverless Jen...

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.

Oleg Nenashev

October 30, 2019
Tweet

More Decks by Oleg Nenashev

Other Decks in Technology

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. • CloudBees Jenkins

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

    Disclaimer: Opinions are mine; typos are mine
  6. © 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
  7. © 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
  8. © 2019 CloudBees, Inc. All Rights Reserved. • Pipeline-as-Code •

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

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

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

    – Kohsuke Kawaguchi, “Jenkins: Shifting Gears” https://jenkins.io/blog/2018/08/31/shifting-gears/ 12
  12. © 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
  13. © 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
  14. © 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 ?
  15. © 2019 CloudBees, Inc. All Rights Reserved. 21 • AWESOME

    (c) • Cloud native • K8s native • Scalable • Designed for CD • Moving fast Jenkins X 2.x is…
  16. © 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
  17. © 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
  18. © 2019 CloudBees, Inc. All Rights Reserved. Master as a

    SPoF Macroservice 25 Permanent agents On-demand agents from cloud providers Web UI Jenkins Master
  19. © 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
  20. © 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
  21. © 2019 CloudBees, Inc. All Rights Reserved. 30 STDOUT/STDERR Workspace

    External storage Workspace Jenkinsfile Configuration (WAR, plugins, settings)
  22. © 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
  23. © 2019 CloudBees, Inc. All Rights Reserved. Usage in Docker

    32 docker run --rm \ -v $(pwd)/Jenkinsfile:/workspace/Jenkinsfile \ jenkins4eval/jenkinsfile-runner* * or another image….
  24. © 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
  25. © 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
  26. © 2019 CloudBees, Inc. All Rights Reserved. But 38 Triggers

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

    Webhook receivers Log services Result Storage Web UI
  28. © 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
  29. © 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
  30. © 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
  31. © 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
  32. © 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
  33. © 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
  34. © 2019 CloudBees, Inc. All Rights Reserved. Jenkins X 1.x.

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

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

    https://github.com/jonico/jenkinsfile-runner-github-actions
  37. © 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
  38. © 2019 CloudBees, Inc. All Rights Reserved. Demo 1 61

    codeship-steps.yml codeship-services.yml Jenkinsfile https://github.com/oleg-nenashev/codeship-jenkinsfile
  39. © 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
  40. © 2019 CloudBees, Inc. All Rights Reserved. Example 2. Building

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

    • GitHub Actions • CloudBees CodeShip We talked about… 67
  42. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfile Runner Test

    Framework https://github.com/jenkinsci/jenkinsfile-runner-test-framework • Custom WAR Packager • Docker • shUnit2 72
  43. © 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
  44. © 2019 CloudBees, Inc. All Rights Reserved. Jenkinsfile Runner Test

    Framework Jenkinsfile Runner packages Jenkinsfiles Pipeline libraries 74 Tests
  45. © 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
  46. © 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
  47. © 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
  48. © 2019 CloudBees, Inc. All Rights Reserved. Contacts: E-mail: [email protected]

    GitHub: oleg-nenashev Twitter: @oleg_nenashev QUESTIONS?