SlideShare a Scribd company logo
Building a (resumable and extensible)
DSL with Apache Groovy
Jesse Glick
CloudBees, Inc.
@tyvole
Introduction
About Me
● Longtime Jenkins core contributor
● Primary developer on Jenkins Pipeline
○ Created initial version in collaboration with Kohsuke Kawaguchi, father of Jenkins
● Previously active in NetBeans (module & project systems), Ant
Meet Jenkins Pipeline
● A new “project type” in Jenkins.
● Defines an explicit series of behaviors, implemented in code.
● Generally checked into source control as a Jenkinsfile.
● Resumability and durability of the pipeline state.
● DSL extensible for end-users and plugin authors alike.
Meet Jenkins Pipeline
node {
stage('Build') {sh 'mvn -B clean package'}
stage('Test') {sh 'mvn verify'}
stage('Deploy') {sh 'mvn release'}
}
Meet Jenkins Pipeline
def image
stage('Build Container') {
image = docker.build('pipeline-demo:apacheconeu')
}
stage('Verify Container') {
image.inside {sh './self-test.sh'}
}
Meet Jenkins Pipeline
Meet Jenkins Pipeline
Design Requirements
Technology Constraints
● Must run on the Java Virtual Machine
○ Groovy was already familiar from other Jenkins scripting features
○ But must be able to restrict access to Jenkins internals
● Compatible with Jenkins domain concepts
○ Plugins working with “nodes”, “workspaces”, &c. can be migrated naturally
● Allow the creation of a domain-specific language (DSL)
● A DSL which end-users can adopt quickly
○ Enable modeling control flow in a single script instead of multiple job configurations
● A DSL which plugin developers can extend in different directions
○ Support new “steps” via existing “extension point” mechanism used by Jenkins plugins
● Pause and resume execution
○ Survive a Jenkins master restart
Desired Features
Why create a DSL?
● Easier to model a continuous delivery pipeline “as code”
○ Developers tend to express complex concepts efficiently in source code
○ Easy to express continuous delivery logic using imperative programming constructs
○ Describing a pipeline in pseudo-code would look a lot like the Pipeline DSL
● Easily understood metaphors for extensibility
○ New “steps” provided by plugins logically integrate into a Pipeline script
Prior art
● Job DSL plugin
○ Groovy DSL for creating job definitions programmatically
○ No impact on runtime behavior (“builds”)
● Build Flow plugin
○ Groovy DSL for orchestrating “downstream” project builds
○ Not self-contained: build details must be configured & stored separately
○ If Jenkins needs to be restarted, the “flow” halts
● Jenkow plugin
○ BPMN-based workflow interpreter with GUI configuration
○ Failed to get much adoption
Touring the
Implementation
Continuation Passing Style
● All Groovy methods calls, loops, &c. translated to “continuations”
○ Uses stock compiler with a CompilationCustomizer
○ Special exception type CpsCallableInvocation denotes transfer of control
● The Jenkins build runs an interpreter loop
○ CPS-transformed methods may call “native” Java/Groovy functions, or “steps”
● Currently the only implementation of “Pipeline engine” extension point
compiler inserts hook
runtime uses continuations
Serialization of program state
● Program state saved periodically from interpreter
○ When Jenkins restarts, interpreter loop resumes running where it left off
● Local variables/values must be java.io.Serializable
○ Unless inside a @NonCPS (“native”) method
● Uses JBoss Marshalling River for features not in Java serialization
○ Extension point to replace references to “live” model objects with “pickles”
restart here (×5)
running
closure
Thread behavior
● Build runs in at most one native thread
○ From a thread pool, so zero native resources consumed when sleeping
● parallel step (fork + join) uses coöperative multitasking
● All Groovy code runs on Jenkins master
○ “Real work” is done in external processes, typically on remote agents
○ node {…} block merely sets a connection protocol for nested sh/bat steps
● Block-scoped steps may pass information via dynamic scope
○ Example: environment variables
Script security
● Do not want scripts making arbitrary Java API calls or accessing local system
○ Yet some trusted users should be able to access Jenkins internal APIs
● “Sandbox”: another CompilationCustomizer to insert security checks
○ Before every method/constructor/field access
○ Implementation shared with several other Groovy-based features in Jenkins
● Stock whitelist in product, plus per-site additions
● Libraries configured by an administrator are trusted
Extension by plugins
● Step extension point permits any plugin to add a new “built-in” function
● Can take named parameters
○ polymorphic structures & lists
○ optional “block” (Closure)
● StepExecution can return immediately, or start something then go to sleep
○ Asynchronous execution terminated with a callback: result object, or exception
● Blocks may be run 0+ times and given context (e.g., a console highlighter)
● Work in progress: StepExecution implemented in Groovy
○ Can call other steps, which may be asynchronous
○ Handy for aggregating lower-level steps into a convenient wrapper
● Arbitrary DSLs also possible
○ but, GUI & tool support is weaker
Groovy libraries
● Reusable code via Pipeline library system
○ Global libraries configured by administrators
○ Per-folder libraries configured by team
○ Or config-free: @Library('github.com/cloudbeers/multibranch-demo-lib') _
● Specify version in SCM (@1.3, @abc1234) or float (@master)
● Define class libraries: src/org/myorg/jenkins/Lib.groovy
● Or variables/functions: src/utils.groovy
● Global libraries may use “Grape” system to load anything in Maven Central
○ @Grab('com.google.guava:guava:19.0') import
com.google.common.base.CharMatcher
Auto-generated documentation
● Extension point for plugins to provide built-in help
● Structure of step parameters introspected
● In-product help accepts configuration forms similar to rest of Jenkins
Snippet Generator
Pipeline Step Reference jenkins.io/doc/pipeline/steps
The Good,
The Bad,
The Groovy
Useful Groovy features
● Smooth integration of Java APIs
● Flexible syntax (named vs. positional parameters, closures, …)
● CompilationCustomizer
CPS & Sandbox vs. Groovy Challenges
● DefaultGroovyMethods helpers taking a Closure do not work
○ [1, 2, 3].each {x -> sh "make world${x}"} → FAIL
● Most java.util.Iterator implementations are not Serializable
○ for (x in [1, 2, 3]) {sh "make world${x}"} → OK (special-cased)
○ for (x in [1, 2, 3, 4, 5].subList(0, 3)) {sh "make world${x}"} → FAIL
● No CPS translation possible for a constructor
● Finding the actual call site for whitelist lookup is really hard
○ GroovyObject.getProperty, coercions, GString, Closure.delegate, curry, …
● More exotic language constructs not yet translated in CPS
○ Tuple assignment, spread operator, method pointer, obj as Interface, …
● Summary: Groovy is far more complex than initially realized
○ and CPS transformation is hard to develop & debug
Groovy runtime challenges/roadblocks
● Leaks, leaks, leaks
○ Groovy is full of caches which do not let go of class loaders
○ Java has a few, too
○ SoftReferences get cleared…eventually (after your heap is already huge)
○ so Pipeline resorts to tricks to unset fields
● Compilation is expensive
○ not just syntactic parsing, lots of class loading to resolve symbols
○ not currently being cached—under consideration
Future Development
Declarative Pipeline
● Easier way to write common pipelines
● Friendly to GUI editors
● Lintable
● Escape to script {…}
Resolve closure/iterator issues
● Find a way to override call sites
○ DefaultGroovyMethods.each(Collection, Closure)
○ List.iterator()
Questions
● jenkins.io/doc
● @jenkinsci
● github.com/jenkinsci/pipeline-plugin
● github.com/jenkinsci/workflow-cps-plugin
● github.com/jenkinsci/pipeline-model-definition-plugin
Resources

More Related Content

What's hot

Jenkins, pipeline and docker
Jenkins, pipeline and docker Jenkins, pipeline and docker
Jenkins, pipeline and docker
AgileDenver
 
Jenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Jenkins Days - Workshop - Let's Build a Pipeline - Los AngelesJenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Jenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Andy Pemberton
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
Steffen Gebert
 
Pipeline based deployments on Jenkins
Pipeline based deployments  on JenkinsPipeline based deployments  on Jenkins
Pipeline based deployments on Jenkins
Knoldus Inc.
 
Jenkins Declarative Pipelines 101
Jenkins Declarative Pipelines 101Jenkins Declarative Pipelines 101
Jenkins Declarative Pipelines 101
Malcolm Groves
 
Continuous Delivery - Pipeline as-code
Continuous Delivery - Pipeline as-codeContinuous Delivery - Pipeline as-code
Continuous Delivery - Pipeline as-code
Mike van Vendeloo
 
Jenkins Pipeline @ Scale. Building Automation Frameworks for Systems Integration
Jenkins Pipeline @ Scale. Building Automation Frameworks for Systems IntegrationJenkins Pipeline @ Scale. Building Automation Frameworks for Systems Integration
Jenkins Pipeline @ Scale. Building Automation Frameworks for Systems Integration
Oleg Nenashev
 
Brujug Jenkins pipeline scalability
Brujug Jenkins pipeline scalabilityBrujug Jenkins pipeline scalability
Brujug Jenkins pipeline scalability
Damien Coraboeuf
 
CI/CD on Android project via Jenkins Pipeline
CI/CD on Android project via Jenkins PipelineCI/CD on Android project via Jenkins Pipeline
CI/CD on Android project via Jenkins Pipeline
Veaceslav Gaidarji
 
Pipeline as code using Jenkins -Ministry of Testing
Pipeline as code using Jenkins -Ministry of TestingPipeline as code using Jenkins -Ministry of Testing
Pipeline as code using Jenkins -Ministry of Testing
Swapnil Jadhav
 
sed.pdf
sed.pdfsed.pdf
sed.pdf
MaenAlWedyan
 
Jenkins pipeline as code
Jenkins pipeline as codeJenkins pipeline as code
Jenkins pipeline as code
Mohammad Imran Ansari
 
Voxxed Luxembourd 2016 Jenkins 2.0 et Pipeline as code
Voxxed Luxembourd 2016 Jenkins 2.0 et Pipeline as codeVoxxed Luxembourd 2016 Jenkins 2.0 et Pipeline as code
Voxxed Luxembourd 2016 Jenkins 2.0 et Pipeline as code
Damien Duportal
 
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Codifying the Build and Release Process with a Jenkins Pipeline Shared LibraryCodifying the Build and Release Process with a Jenkins Pipeline Shared Library
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Alvin Huang
 
Continuous Delivery Pipeline with Docker and Jenkins
Continuous Delivery Pipeline with Docker and JenkinsContinuous Delivery Pipeline with Docker and Jenkins
Continuous Delivery Pipeline with Docker and Jenkins
Camilo Ribeiro
 
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandCI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
Troublemaker Khunpech
 
Continuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and JenkinsContinuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and Jenkins
Francesco Bruni
 
Testing with Docker
Testing with DockerTesting with Docker
Testing with Docker
toffermann
 
Building Jenkins Pipelines at Scale
Building Jenkins Pipelines at ScaleBuilding Jenkins Pipelines at Scale
Building Jenkins Pipelines at Scale
Julien Pivotto
 
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Steffen Gebert
 

What's hot (20)

Jenkins, pipeline and docker
Jenkins, pipeline and docker Jenkins, pipeline and docker
Jenkins, pipeline and docker
 
Jenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Jenkins Days - Workshop - Let's Build a Pipeline - Los AngelesJenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Jenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
 
Pipeline based deployments on Jenkins
Pipeline based deployments  on JenkinsPipeline based deployments  on Jenkins
Pipeline based deployments on Jenkins
 
Jenkins Declarative Pipelines 101
Jenkins Declarative Pipelines 101Jenkins Declarative Pipelines 101
Jenkins Declarative Pipelines 101
 
Continuous Delivery - Pipeline as-code
Continuous Delivery - Pipeline as-codeContinuous Delivery - Pipeline as-code
Continuous Delivery - Pipeline as-code
 
Jenkins Pipeline @ Scale. Building Automation Frameworks for Systems Integration
Jenkins Pipeline @ Scale. Building Automation Frameworks for Systems IntegrationJenkins Pipeline @ Scale. Building Automation Frameworks for Systems Integration
Jenkins Pipeline @ Scale. Building Automation Frameworks for Systems Integration
 
Brujug Jenkins pipeline scalability
Brujug Jenkins pipeline scalabilityBrujug Jenkins pipeline scalability
Brujug Jenkins pipeline scalability
 
CI/CD on Android project via Jenkins Pipeline
CI/CD on Android project via Jenkins PipelineCI/CD on Android project via Jenkins Pipeline
CI/CD on Android project via Jenkins Pipeline
 
Pipeline as code using Jenkins -Ministry of Testing
Pipeline as code using Jenkins -Ministry of TestingPipeline as code using Jenkins -Ministry of Testing
Pipeline as code using Jenkins -Ministry of Testing
 
sed.pdf
sed.pdfsed.pdf
sed.pdf
 
Jenkins pipeline as code
Jenkins pipeline as codeJenkins pipeline as code
Jenkins pipeline as code
 
Voxxed Luxembourd 2016 Jenkins 2.0 et Pipeline as code
Voxxed Luxembourd 2016 Jenkins 2.0 et Pipeline as codeVoxxed Luxembourd 2016 Jenkins 2.0 et Pipeline as code
Voxxed Luxembourd 2016 Jenkins 2.0 et Pipeline as code
 
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Codifying the Build and Release Process with a Jenkins Pipeline Shared LibraryCodifying the Build and Release Process with a Jenkins Pipeline Shared Library
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
 
Continuous Delivery Pipeline with Docker and Jenkins
Continuous Delivery Pipeline with Docker and JenkinsContinuous Delivery Pipeline with Docker and Jenkins
Continuous Delivery Pipeline with Docker and Jenkins
 
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day ThailandCI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
 
Continuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and JenkinsContinuous Integration/Deployment with Docker and Jenkins
Continuous Integration/Deployment with Docker and Jenkins
 
Testing with Docker
Testing with DockerTesting with Docker
Testing with Docker
 
Building Jenkins Pipelines at Scale
Building Jenkins Pipelines at ScaleBuilding Jenkins Pipelines at Scale
Building Jenkins Pipelines at Scale
 
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
 

Viewers also liked

Jenkins and Groovy
Jenkins and GroovyJenkins and Groovy
Jenkins and GroovyKiyotaka Oku
 
Super Charged Configuration As Code
Super Charged Configuration As CodeSuper Charged Configuration As Code
Super Charged Configuration As Code
Alan Beale
 
Jenkins Job DSL plugin
Jenkins Job DSL plugin Jenkins Job DSL plugin
Jenkins Job DSL plugin
Nikita Bugrovsky
 
Puppet & Jenkins
Puppet & JenkinsPuppet & Jenkins
Puppet & Jenkins
Matthew Barr
 
Continuous Delivery of Puppet-Based Infrastructure - PuppetConf 2014
Continuous Delivery of Puppet-Based Infrastructure - PuppetConf 2014Continuous Delivery of Puppet-Based Infrastructure - PuppetConf 2014
Continuous Delivery of Puppet-Based Infrastructure - PuppetConf 2014
Puppet
 
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
Gareth Bowles
 
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Puppet
 
Synchronizing parallel delivery flows in jenkins using groovy, build flow and...
Synchronizing parallel delivery flows in jenkins using groovy, build flow and...Synchronizing parallel delivery flows in jenkins using groovy, build flow and...
Synchronizing parallel delivery flows in jenkins using groovy, build flow and...
Andrey Devyatkin
 
Large scale automation with jenkins
Large scale automation with jenkinsLarge scale automation with jenkins
Large scale automation with jenkins
Kohsuke Kawaguchi
 
Writing a Jenkins / Hudson plugin
Writing a Jenkins / Hudson pluginWriting a Jenkins / Hudson plugin
Writing a Jenkins / Hudson plugin
Anthony Dahanne
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
GR8Conf
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
GR8Conf
 
Groovy on Android
Groovy on AndroidGroovy on Android
Groovy on Android
Alexey Zhokhov
 
Groovy in the Cloud
Groovy in the CloudGroovy in the Cloud
Groovy in the Cloud
Daniel Woods
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
Ali Tanwir
 
Ci for-android-apps
Ci for-android-appsCi for-android-apps
Ci for-android-apps
Anthony Dahanne
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
groovy and concurrency
groovy and concurrencygroovy and concurrency
groovy and concurrency
Paul King
 
Spring one 2012 Groovy as a weapon of maas PaaSification
Spring one 2012 Groovy as a weapon of maas PaaSificationSpring one 2012 Groovy as a weapon of maas PaaSification
Spring one 2012 Groovy as a weapon of maas PaaSification
Nenad Bogojevic
 
We thought we were doing continuous delivery and then...
We thought we were doing continuous delivery and then... We thought we were doing continuous delivery and then...
We thought we were doing continuous delivery and then...
Suzie Prince
 

Viewers also liked (20)

Jenkins and Groovy
Jenkins and GroovyJenkins and Groovy
Jenkins and Groovy
 
Super Charged Configuration As Code
Super Charged Configuration As CodeSuper Charged Configuration As Code
Super Charged Configuration As Code
 
Jenkins Job DSL plugin
Jenkins Job DSL plugin Jenkins Job DSL plugin
Jenkins Job DSL plugin
 
Puppet & Jenkins
Puppet & JenkinsPuppet & Jenkins
Puppet & Jenkins
 
Continuous Delivery of Puppet-Based Infrastructure - PuppetConf 2014
Continuous Delivery of Puppet-Based Infrastructure - PuppetConf 2014Continuous Delivery of Puppet-Based Infrastructure - PuppetConf 2014
Continuous Delivery of Puppet-Based Infrastructure - PuppetConf 2014
 
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
 
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
 
Synchronizing parallel delivery flows in jenkins using groovy, build flow and...
Synchronizing parallel delivery flows in jenkins using groovy, build flow and...Synchronizing parallel delivery flows in jenkins using groovy, build flow and...
Synchronizing parallel delivery flows in jenkins using groovy, build flow and...
 
Large scale automation with jenkins
Large scale automation with jenkinsLarge scale automation with jenkins
Large scale automation with jenkins
 
Writing a Jenkins / Hudson plugin
Writing a Jenkins / Hudson pluginWriting a Jenkins / Hudson plugin
Writing a Jenkins / Hudson plugin
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Groovy on Android
Groovy on AndroidGroovy on Android
Groovy on Android
 
Groovy in the Cloud
Groovy in the CloudGroovy in the Cloud
Groovy in the Cloud
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
Ci for-android-apps
Ci for-android-appsCi for-android-apps
Ci for-android-apps
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
groovy and concurrency
groovy and concurrencygroovy and concurrency
groovy and concurrency
 
Spring one 2012 Groovy as a weapon of maas PaaSification
Spring one 2012 Groovy as a weapon of maas PaaSificationSpring one 2012 Groovy as a weapon of maas PaaSification
Spring one 2012 Groovy as a weapon of maas PaaSification
 
We thought we were doing continuous delivery and then...
We thought we were doing continuous delivery and then... We thought we were doing continuous delivery and then...
We thought we were doing continuous delivery and then...
 

Similar to Building an Extensible, Resumable DSL on Top of Apache Groovy

Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015
Kurt Madel
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventures
Frits Van Der Holst
 
Who needs containers in a serverless world
Who needs containers in a serverless worldWho needs containers in a serverless world
Who needs containers in a serverless world
Matthias Luebken
 
GeoServer Developers Workshop
GeoServer Developers WorkshopGeoServer Developers Workshop
GeoServer Developers Workshop
Jody Garnett
 
Jenkins presentation
Jenkins presentationJenkins presentation
Jenkins presentation
Valentin Buryakov
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
Eugene Yokota
 
The Self-Service Developer - GOTOCon CPH
The Self-Service Developer - GOTOCon CPHThe Self-Service Developer - GOTOCon CPH
The Self-Service Developer - GOTOCon CPH
Laszlo Fogas
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Eugene Yokota
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
corehard_by
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
Giacomo Vacca
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsNick Belhomme
 
The Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldThe Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote World
DevOps.com
 
Making your app soar without a container manifest
Making your app soar without a container manifestMaking your app soar without a container manifest
Making your app soar without a container manifest
LibbySchulze
 
Deep dive - Concourse CI/CD and Pipelines
Deep dive  - Concourse CI/CD and PipelinesDeep dive  - Concourse CI/CD and Pipelines
Deep dive - Concourse CI/CD and Pipelines
Syed Imam
 
Dockerized maven
Dockerized mavenDockerized maven
Dockerized maven
Matthias Bertschy
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
Samuel Chow
 
ContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven Infrastructure
Yury Tsarev
 
Introduction to Performance APIs
Introduction to Performance APIsIntroduction to Performance APIs
Introduction to Performance APIs
Shogo Sensui
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil Framework
VeilFramework
 
Nodejs
NodejsNodejs

Similar to Building an Extensible, Resumable DSL on Top of Apache Groovy (20)

Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventures
 
Who needs containers in a serverless world
Who needs containers in a serverless worldWho needs containers in a serverless world
Who needs containers in a serverless world
 
GeoServer Developers Workshop
GeoServer Developers WorkshopGeoServer Developers Workshop
GeoServer Developers Workshop
 
Jenkins presentation
Jenkins presentationJenkins presentation
Jenkins presentation
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
 
The Self-Service Developer - GOTOCon CPH
The Self-Service Developer - GOTOCon CPHThe Self-Service Developer - GOTOCon CPH
The Self-Service Developer - GOTOCon CPH
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
 
Mastering selenium for automated acceptance tests
Mastering selenium for automated acceptance testsMastering selenium for automated acceptance tests
Mastering selenium for automated acceptance tests
 
The Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldThe Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote World
 
Making your app soar without a container manifest
Making your app soar without a container manifestMaking your app soar without a container manifest
Making your app soar without a container manifest
 
Deep dive - Concourse CI/CD and Pipelines
Deep dive  - Concourse CI/CD and PipelinesDeep dive  - Concourse CI/CD and Pipelines
Deep dive - Concourse CI/CD and Pipelines
 
Dockerized maven
Dockerized mavenDockerized maven
Dockerized maven
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
 
ContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven Infrastructure
 
Introduction to Performance APIs
Introduction to Performance APIsIntroduction to Performance APIs
Introduction to Performance APIs
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil Framework
 
Nodejs
NodejsNodejs
Nodejs
 

Recently uploaded

Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 

Recently uploaded (20)

Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 

Building an Extensible, Resumable DSL on Top of Apache Groovy

  • 1. Building a (resumable and extensible) DSL with Apache Groovy Jesse Glick CloudBees, Inc. @tyvole
  • 3. About Me ● Longtime Jenkins core contributor ● Primary developer on Jenkins Pipeline ○ Created initial version in collaboration with Kohsuke Kawaguchi, father of Jenkins ● Previously active in NetBeans (module & project systems), Ant
  • 4. Meet Jenkins Pipeline ● A new “project type” in Jenkins. ● Defines an explicit series of behaviors, implemented in code. ● Generally checked into source control as a Jenkinsfile. ● Resumability and durability of the pipeline state. ● DSL extensible for end-users and plugin authors alike.
  • 5. Meet Jenkins Pipeline node { stage('Build') {sh 'mvn -B clean package'} stage('Test') {sh 'mvn verify'} stage('Deploy') {sh 'mvn release'} }
  • 6. Meet Jenkins Pipeline def image stage('Build Container') { image = docker.build('pipeline-demo:apacheconeu') } stage('Verify Container') { image.inside {sh './self-test.sh'} }
  • 10. Technology Constraints ● Must run on the Java Virtual Machine ○ Groovy was already familiar from other Jenkins scripting features ○ But must be able to restrict access to Jenkins internals ● Compatible with Jenkins domain concepts ○ Plugins working with “nodes”, “workspaces”, &c. can be migrated naturally ● Allow the creation of a domain-specific language (DSL)
  • 11. ● A DSL which end-users can adopt quickly ○ Enable modeling control flow in a single script instead of multiple job configurations ● A DSL which plugin developers can extend in different directions ○ Support new “steps” via existing “extension point” mechanism used by Jenkins plugins ● Pause and resume execution ○ Survive a Jenkins master restart Desired Features
  • 12. Why create a DSL? ● Easier to model a continuous delivery pipeline “as code” ○ Developers tend to express complex concepts efficiently in source code ○ Easy to express continuous delivery logic using imperative programming constructs ○ Describing a pipeline in pseudo-code would look a lot like the Pipeline DSL ● Easily understood metaphors for extensibility ○ New “steps” provided by plugins logically integrate into a Pipeline script
  • 13. Prior art ● Job DSL plugin ○ Groovy DSL for creating job definitions programmatically ○ No impact on runtime behavior (“builds”) ● Build Flow plugin ○ Groovy DSL for orchestrating “downstream” project builds ○ Not self-contained: build details must be configured & stored separately ○ If Jenkins needs to be restarted, the “flow” halts ● Jenkow plugin ○ BPMN-based workflow interpreter with GUI configuration ○ Failed to get much adoption
  • 15. Continuation Passing Style ● All Groovy methods calls, loops, &c. translated to “continuations” ○ Uses stock compiler with a CompilationCustomizer ○ Special exception type CpsCallableInvocation denotes transfer of control ● The Jenkins build runs an interpreter loop ○ CPS-transformed methods may call “native” Java/Groovy functions, or “steps” ● Currently the only implementation of “Pipeline engine” extension point
  • 16. compiler inserts hook runtime uses continuations
  • 17. Serialization of program state ● Program state saved periodically from interpreter ○ When Jenkins restarts, interpreter loop resumes running where it left off ● Local variables/values must be java.io.Serializable ○ Unless inside a @NonCPS (“native”) method ● Uses JBoss Marshalling River for features not in Java serialization ○ Extension point to replace references to “live” model objects with “pickles”
  • 19. Thread behavior ● Build runs in at most one native thread ○ From a thread pool, so zero native resources consumed when sleeping ● parallel step (fork + join) uses coöperative multitasking ● All Groovy code runs on Jenkins master ○ “Real work” is done in external processes, typically on remote agents ○ node {…} block merely sets a connection protocol for nested sh/bat steps ● Block-scoped steps may pass information via dynamic scope ○ Example: environment variables
  • 20.
  • 21. Script security ● Do not want scripts making arbitrary Java API calls or accessing local system ○ Yet some trusted users should be able to access Jenkins internal APIs ● “Sandbox”: another CompilationCustomizer to insert security checks ○ Before every method/constructor/field access ○ Implementation shared with several other Groovy-based features in Jenkins ● Stock whitelist in product, plus per-site additions ● Libraries configured by an administrator are trusted
  • 22. Extension by plugins ● Step extension point permits any plugin to add a new “built-in” function ● Can take named parameters ○ polymorphic structures & lists ○ optional “block” (Closure) ● StepExecution can return immediately, or start something then go to sleep ○ Asynchronous execution terminated with a callback: result object, or exception ● Blocks may be run 0+ times and given context (e.g., a console highlighter) ● Work in progress: StepExecution implemented in Groovy ○ Can call other steps, which may be asynchronous ○ Handy for aggregating lower-level steps into a convenient wrapper ● Arbitrary DSLs also possible ○ but, GUI & tool support is weaker
  • 23. Groovy libraries ● Reusable code via Pipeline library system ○ Global libraries configured by administrators ○ Per-folder libraries configured by team ○ Or config-free: @Library('github.com/cloudbeers/multibranch-demo-lib') _ ● Specify version in SCM (@1.3, @abc1234) or float (@master) ● Define class libraries: src/org/myorg/jenkins/Lib.groovy ● Or variables/functions: src/utils.groovy ● Global libraries may use “Grape” system to load anything in Maven Central ○ @Grab('com.google.guava:guava:19.0') import com.google.common.base.CharMatcher
  • 24. Auto-generated documentation ● Extension point for plugins to provide built-in help ● Structure of step parameters introspected ● In-product help accepts configuration forms similar to rest of Jenkins
  • 26.
  • 27. Pipeline Step Reference jenkins.io/doc/pipeline/steps
  • 29. Useful Groovy features ● Smooth integration of Java APIs ● Flexible syntax (named vs. positional parameters, closures, …) ● CompilationCustomizer
  • 30. CPS & Sandbox vs. Groovy Challenges ● DefaultGroovyMethods helpers taking a Closure do not work ○ [1, 2, 3].each {x -> sh "make world${x}"} → FAIL ● Most java.util.Iterator implementations are not Serializable ○ for (x in [1, 2, 3]) {sh "make world${x}"} → OK (special-cased) ○ for (x in [1, 2, 3, 4, 5].subList(0, 3)) {sh "make world${x}"} → FAIL ● No CPS translation possible for a constructor ● Finding the actual call site for whitelist lookup is really hard ○ GroovyObject.getProperty, coercions, GString, Closure.delegate, curry, … ● More exotic language constructs not yet translated in CPS ○ Tuple assignment, spread operator, method pointer, obj as Interface, … ● Summary: Groovy is far more complex than initially realized ○ and CPS transformation is hard to develop & debug
  • 31. Groovy runtime challenges/roadblocks ● Leaks, leaks, leaks ○ Groovy is full of caches which do not let go of class loaders ○ Java has a few, too ○ SoftReferences get cleared…eventually (after your heap is already huge) ○ so Pipeline resorts to tricks to unset fields ● Compilation is expensive ○ not just syntactic parsing, lots of class loading to resolve symbols ○ not currently being cached—under consideration
  • 33. Declarative Pipeline ● Easier way to write common pipelines ● Friendly to GUI editors ● Lintable ● Escape to script {…}
  • 34. Resolve closure/iterator issues ● Find a way to override call sites ○ DefaultGroovyMethods.each(Collection, Closure) ○ List.iterator()
  • 36. ● jenkins.io/doc ● @jenkinsci ● github.com/jenkinsci/pipeline-plugin ● github.com/jenkinsci/workflow-cps-plugin ● github.com/jenkinsci/pipeline-model-definition-plugin Resources