SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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 AngelesAndy Pemberton
 
Pipeline based deployments on Jenkins
Pipeline based deployments  on JenkinsPipeline based deployments  on Jenkins
Pipeline based deployments on JenkinsKnoldus Inc.
 
Jenkins Declarative Pipelines 101
Jenkins Declarative Pipelines 101Jenkins Declarative Pipelines 101
Jenkins Declarative Pipelines 101Malcolm Groves
 
Continuous Delivery - Pipeline as-code
Continuous Delivery - Pipeline as-codeContinuous Delivery - Pipeline as-code
Continuous Delivery - Pipeline as-codeMike 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 IntegrationOleg Nenashev
 
Brujug Jenkins pipeline scalability
Brujug Jenkins pipeline scalabilityBrujug Jenkins pipeline scalability
Brujug Jenkins pipeline scalabilityDamien 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 PipelineVeaceslav 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 TestingSwapnil Jadhav
 
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 codeDamien 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 LibraryAlvin 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 JenkinsCamilo 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 ThailandTroublemaker 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 JenkinsFrancesco Bruni
 
Testing with Docker
Testing with DockerTesting with Docker
Testing with Dockertoffermann
 
Building Jenkins Pipelines at Scale
Building Jenkins Pipelines at ScaleBuilding Jenkins Pipelines at Scale
Building Jenkins Pipelines at ScaleJulien 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
 

Was ist angesagt? (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)
 

Andere mochten auch

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 CodeAlan Beale
 
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 2014Puppet
 
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 jenkinsKohsuke Kawaguchi
 
Writing a Jenkins / Hudson plugin
Writing a Jenkins / Hudson pluginWriting a Jenkins / Hudson plugin
Writing a Jenkins / Hudson pluginAnthony Dahanne
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with GroovyGR8Conf
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean CodeGR8Conf
 
Groovy in the Cloud
Groovy in the CloudGroovy in the Cloud
Groovy in the CloudDaniel Woods
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with GroovyAli Tanwir
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvmArnaud Giuliani
 
groovy and concurrency
groovy and concurrencygroovy and concurrency
groovy and concurrencyPaul 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 PaaSificationNenad 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
 

Andere mochten auch (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...
 

Ähnlich wie 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 2015Kurt 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 adventuresFrits 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 worldMatthias Luebken
 
GeoServer Developers Workshop
GeoServer Developers WorkshopGeoServer Developers Workshop
GeoServer Developers WorkshopJody Garnett
 
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 serverEugene Yokota
 
The Self-Service Developer - GOTOCon CPH
The Self-Service Developer - GOTOCon CPHThe Self-Service Developer - GOTOCon CPH
The Self-Service Developer - GOTOCon CPHLaszlo 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'acorehard_by
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationGiacomo 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 WorldDevOps.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 manifestLibbySchulze
 
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 PipelinesSyed Imam
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tipsSamuel Chow
 
ContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureYury Tsarev
 
Introduction to Performance APIs
Introduction to Performance APIsIntroduction to Performance APIs
Introduction to Performance APIsShogo Sensui
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil FrameworkVeilFramework
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 

Kürzlich hochgeladen (20)

Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 

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