SlideShare a Scribd company logo
1 of 26
Download to read offline
Jenkins User Conference San Francisco #jenkinsconf
Supercharged Configuration As Code
Bulk Updates with Job DSL and System Groovy
Alan Beale
Chicago Trading Company
!
!
October 23, 2014
#jenkinsconf
Jenkins User Conference San Francisco #jenkinsconf
Who Am I
• Alan Beale
Build Engineer @ Chicago Trading Company
The statements, remarks and conclusions of this
presentation are my own and do not represent the views
of my employer, CTC Trading Group, L.L.C. (“CTC”).
Jenkins User Conference San Francisco #jenkinsconf
Have you ever found a
change that you need to
apply to 100 jobs?
Jenkins User Conference San Francisco #jenkinsconf
• Job DSL is a plugin that allows users to create job
configurations with a groovy domain specific
language
• System groovy scripts are groovy scripts that have
access the the Jenkins.instance calling various parts
of the Jenkins API
Jenkins User Conference San Francisco #jenkinsconf
Observations about build jobs
• Jobs Change over Time
• Most jobs are like other jobs
Jenkins User Conference San Francisco #jenkinsconf
Jobs Change Over Time
• Correctness Changes
• Bug Fixes
• Complexity Increase
Jenkins User Conference San Francisco #jenkinsconf
Most Jobs are Similar
• Small number of themes with structured variation
Jenkins User Conference San Francisco #jenkinsconf
Example of Job Themes
• Continuous Integration Jobs
• Gerrit Verification Jobs
• Release Jobs
• Privileged SCM Task Automation
Jenkins User Conference San Francisco #jenkinsconf
How do these observations help?
• Job DSL enables us to using coding techniques to
create job configurations
• System groovy scripts enable use to automate
repeated calls to jobs
Jenkins User Conference San Francisco #jenkinsconf
Player Piano
• Our metaphor for bulk job regeneration
Jenkins User Conference San Francisco #jenkinsconf
The Piano Roll
• Controls the sound of the piano
• Orchestrates the automation of job recreation
Jenkins User Conference San Francisco #jenkinsconf
Job DSL for gradle build
job {
name "git-gradle-simple-build"
scm {
git('/Users/alanbeale/sandbox/samples/java/basic',
'*/master' )
}
steps {
gradle ( "build", null, true )
}
}
Jenkins User Conference San Francisco #jenkinsconf
Evolution Example
job {
name "git-gradle-build-with-worspace-option"
scm {
git('/Users/alanbeale/sandbox/samples/java/basic',
‘*/master')
}
steps {
gradle ( "build", null, true
){ node -> //hudson.plugins.gradle.Gradle
node/useWorkspaceAsHome(true)
}
}
}
Jenkins User Conference San Francisco #jenkinsconf
Add Gerrit Trigger
• https://github.com/bealeaj1214/jenkins-juc-
job-dsl-bulk-regeneration/blob/master/src/
examples/jobdsl/scm-gradle-gerrit-build.jobDSL
Jenkins User Conference San Francisco #jenkinsconf
Repeated elements
• Job Name	

• Git URL	

• Gerrit Trigger Project
Jenkins User Conference San Francisco #jenkinsconf
Towards Job Factory
• Factor out common operations
• Parameterize calling Job DSL
Jenkins User Conference San Francisco #jenkinsconf
Create Utility class
• jobdsl.JobUtilities methods	

• setupGradleGerritJobName()	

• setupGerritScm()	

• setupGerritTrigger()	

• setupGradleBuild()
Jenkins User Conference San Francisco #jenkinsconf
JobUtilities.groovy
• https://github.com/bealeaj1214/jenkins-juc-
job-dsl-bulk-regeneration/blob/master/src/
main/groovy/jobdsl/JobUtilities.groovy
Jenkins User Conference San Francisco #jenkinsconf
generator job DSL
• https://github.com/bealeaj1214/jenkins-juc-
job-dsl-bulk-regeneration/blob/master/src/
generator/jobdsl/
seed4GradleGerritJobs.jobDSL
Jenkins User Conference San Francisco #jenkinsconf
Part 2 : System Groovy
Jenkins User Conference San Francisco #jenkinsconf
Regeneration script
import jenkins.model.*
!
import hudson.model.*
!
def jenkins = jenkins.model.Jenkins.instance
def jobGeneratorName='gradle-gerrit-job-generator'
def jobGenerator = jenkins.getItem(jobGeneratorName)
def projectParamName ='PROJECT_NAME'
def projectParamValue=‘sample/java/library'
!
if(jobGenerator){
boolean buildQueued =
jobGenerator.scheduleBuild( 5,
new Cause.UserIdCause(),
new ParametersAction(
new StringParameterValue(projectParamName, projectParamValue)
)
)
}
Jenkins User Conference San Francisco #jenkinsconf
Regenerate from existing job name
import jenkins.model.*
!
import hudson.model.*
!
def jenkins = jenkins.model.Jenkins.instance
def jobGeneratorName='gradle-gerrit-job-generator'
def jobGenerator = jenkins.getItem(jobGeneratorName)
def projectParamName ='PROJECT_NAME'
def jobs = jenkins.getItems()
!
def gerritJobs = jobs.findAll { job ->
job.name.endsWith('gradle-gerrit')
}
!
def projectNames =gerritJobs.collect { item ->
item.triggers.values().find {
it.class.simpleName =='GerritTrigger'
}. gerritProjects[0].pattern
}
!
if(jobGenerator){
projectNames.each { projectName ->
boolean buildQueued =
jobGenerator.scheduleBuild( 5,
new Cause.UserIdCause(),
new ParametersAction(
new StringParameterValue( projectParamName,projectName)
)
)
}
}
Jenkins User Conference San Francisco #jenkinsconf
Summary
• Job DSL enables precise control
• Define parameterized Job Generator (the piano)
Jenkins User Conference San Francisco #jenkinsconf
Summary
• System Groovy Jobs
• automates calling job generator in bulk
(piano roll)
Jenkins User Conference San Francisco #jenkinsconf
Thank You To Our Sponsors
Platinum Gold
Silver
Corporate
Jenkins User Conference San Francisco #jenkinsconf
Thank You
• Source Code at https://github.com/bealeaj1214/
jenkins-juc-job-dsl-bulk-regeneration

More Related Content

What's hot

What's hot (20)

Jenkins Best Practices
Jenkins Best PracticesJenkins Best Practices
Jenkins Best Practices
 
Dockercon2015 bamboo
Dockercon2015 bambooDockercon2015 bamboo
Dockercon2015 bamboo
 
Gradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build timesGradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build times
 
JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Je...
JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Je...JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Je...
JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Je...
 
Stockholm Jenkins Area Meetup, March 2017
Stockholm Jenkins Area Meetup, March 2017Stockholm Jenkins Area Meetup, March 2017
Stockholm Jenkins Area Meetup, March 2017
 
GitHub Actions in action
GitHub Actions in actionGitHub Actions in action
GitHub Actions in action
 
CI/CD with GitHub Actions
CI/CD with GitHub ActionsCI/CD with GitHub Actions
CI/CD with GitHub Actions
 
Jfokus 2017 - The DevOps Disaster
Jfokus 2017 - The DevOps Disaster Jfokus 2017 - The DevOps Disaster
Jfokus 2017 - The DevOps Disaster
 
Code review vs pull request
Code review vs pull requestCode review vs pull request
Code review vs pull request
 
Automated android testing using jenkins ci
Automated android testing using jenkins ciAutomated android testing using jenkins ci
Automated android testing using jenkins ci
 
Container based CI/CD on GitHub Actions
Container based CI/CD on GitHub ActionsContainer based CI/CD on GitHub Actions
Container based CI/CD on GitHub Actions
 
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)
 
Next-gen DevOps engineering with Docker and Kubernetes by Antons Kranga
Next-gen DevOps engineering with Docker and Kubernetes by Antons KrangaNext-gen DevOps engineering with Docker and Kubernetes by Antons Kranga
Next-gen DevOps engineering with Docker and Kubernetes by Antons Kranga
 
Practical continuous quality gates for development process
Practical continuous quality gates for development processPractical continuous quality gates for development process
Practical continuous quality gates for development process
 
From Virtual Machines to Containers
From Virtual Machines to ContainersFrom Virtual Machines to Containers
From Virtual Machines to Containers
 
Github in Action
Github in ActionGithub in Action
Github in Action
 
Grooving with Jenkins
Grooving with JenkinsGrooving with Jenkins
Grooving with Jenkins
 
GitHub Actions with Node.js
GitHub Actions with Node.jsGitHub Actions with Node.js
GitHub Actions with Node.js
 
Jenkins presentation
Jenkins presentationJenkins presentation
Jenkins presentation
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
 

Viewers also liked

Viewers also liked (14)

Jenkins plugins
Jenkins pluginsJenkins plugins
Jenkins plugins
 
Jenkins Job DSL plugin
Jenkins Job DSL plugin Jenkins Job DSL plugin
Jenkins Job DSL plugin
 
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
 
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...
 
Writing a Jenkins / Hudson plugin
Writing a Jenkins / Hudson pluginWriting a Jenkins / Hudson plugin
Writing a Jenkins / Hudson plugin
 
groovy and concurrency
groovy and concurrencygroovy and concurrency
groovy and concurrency
 
Jenkins 101: Continuos Integration with Jenkins
Jenkins 101: Continuos Integration with JenkinsJenkins 101: Continuos Integration with Jenkins
Jenkins 101: Continuos Integration with Jenkins
 
Jenkins Scriptler in 90mins
Jenkins Scriptler in 90minsJenkins Scriptler in 90mins
Jenkins Scriptler in 90mins
 
Groovy Maven Builds
Groovy Maven BuildsGroovy Maven Builds
Groovy Maven Builds
 
Continuous Development Pipeline
Continuous Development PipelineContinuous Development Pipeline
Continuous Development Pipeline
 
Building an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache GroovyBuilding an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache Groovy
 
Jenkins days workshop pipelines - Eric Long
Jenkins days workshop  pipelines - Eric LongJenkins days workshop  pipelines - Eric Long
Jenkins days workshop pipelines - Eric Long
 
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
 

Similar to Super Charged Configuration As Code

413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow
Andy Pemberton
 

Similar to Super Charged Configuration As Code (20)

Configuration as Code: The Job DSL Plugin
Configuration as Code: The Job DSL PluginConfiguration as Code: The Job DSL Plugin
Configuration as Code: The Job DSL Plugin
 
Jenkins User Conference 2014
Jenkins User Conference 2014Jenkins User Conference 2014
Jenkins User Conference 2014
 
Juc boston2014.pptx
Juc boston2014.pptxJuc boston2014.pptx
Juc boston2014.pptx
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines
 
Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2
 
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 vs. AWS CodePipeline
Jenkins vs. AWS CodePipelineJenkins vs. AWS CodePipeline
Jenkins vs. AWS CodePipeline
 
JUC Europe 2015: From Virtual Machines to Containers: Achieving Continuous In...
JUC Europe 2015: From Virtual Machines to Containers: Achieving Continuous In...JUC Europe 2015: From Virtual Machines to Containers: Achieving Continuous In...
JUC Europe 2015: From Virtual Machines to Containers: Achieving Continuous In...
 
413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow
 
Jenkins as a Service - Code all the way down
Jenkins as a Service - Code all the way downJenkins as a Service - Code all the way down
Jenkins as a Service - Code all the way down
 
Testing Salesforce at Cloud Scale
Testing Salesforce at Cloud ScaleTesting Salesforce at Cloud Scale
Testing Salesforce at Cloud Scale
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
 
Gluecon 2018 JaC
Gluecon 2018 JaCGluecon 2018 JaC
Gluecon 2018 JaC
 
JUC Europe 2015: Hey! What Did We Just Release?
JUC Europe 2015: Hey! What Did We Just Release?JUC Europe 2015: Hey! What Did We Just Release?
JUC Europe 2015: Hey! What Did We Just Release?
 
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
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
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)
 
DEVOPS LIVE 2018 JaC
DEVOPS LIVE 2018 JaCDEVOPS LIVE 2018 JaC
DEVOPS LIVE 2018 JaC
 
Jenkins State of union 2013
Jenkins State of union 2013Jenkins State of union 2013
Jenkins State of union 2013
 
Jenkins-CI
Jenkins-CIJenkins-CI
Jenkins-CI
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
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
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 

Super Charged Configuration As Code

  • 1. Jenkins User Conference San Francisco #jenkinsconf Supercharged Configuration As Code Bulk Updates with Job DSL and System Groovy Alan Beale Chicago Trading Company ! ! October 23, 2014 #jenkinsconf
  • 2. Jenkins User Conference San Francisco #jenkinsconf Who Am I • Alan Beale Build Engineer @ Chicago Trading Company The statements, remarks and conclusions of this presentation are my own and do not represent the views of my employer, CTC Trading Group, L.L.C. (“CTC”).
  • 3. Jenkins User Conference San Francisco #jenkinsconf Have you ever found a change that you need to apply to 100 jobs?
  • 4. Jenkins User Conference San Francisco #jenkinsconf • Job DSL is a plugin that allows users to create job configurations with a groovy domain specific language • System groovy scripts are groovy scripts that have access the the Jenkins.instance calling various parts of the Jenkins API
  • 5. Jenkins User Conference San Francisco #jenkinsconf Observations about build jobs • Jobs Change over Time • Most jobs are like other jobs
  • 6. Jenkins User Conference San Francisco #jenkinsconf Jobs Change Over Time • Correctness Changes • Bug Fixes • Complexity Increase
  • 7. Jenkins User Conference San Francisco #jenkinsconf Most Jobs are Similar • Small number of themes with structured variation
  • 8. Jenkins User Conference San Francisco #jenkinsconf Example of Job Themes • Continuous Integration Jobs • Gerrit Verification Jobs • Release Jobs • Privileged SCM Task Automation
  • 9. Jenkins User Conference San Francisco #jenkinsconf How do these observations help? • Job DSL enables us to using coding techniques to create job configurations • System groovy scripts enable use to automate repeated calls to jobs
  • 10. Jenkins User Conference San Francisco #jenkinsconf Player Piano • Our metaphor for bulk job regeneration
  • 11. Jenkins User Conference San Francisco #jenkinsconf The Piano Roll • Controls the sound of the piano • Orchestrates the automation of job recreation
  • 12. Jenkins User Conference San Francisco #jenkinsconf Job DSL for gradle build job { name "git-gradle-simple-build" scm { git('/Users/alanbeale/sandbox/samples/java/basic', '*/master' ) } steps { gradle ( "build", null, true ) } }
  • 13. Jenkins User Conference San Francisco #jenkinsconf Evolution Example job { name "git-gradle-build-with-worspace-option" scm { git('/Users/alanbeale/sandbox/samples/java/basic', ‘*/master') } steps { gradle ( "build", null, true ){ node -> //hudson.plugins.gradle.Gradle node/useWorkspaceAsHome(true) } } }
  • 14. Jenkins User Conference San Francisco #jenkinsconf Add Gerrit Trigger • https://github.com/bealeaj1214/jenkins-juc- job-dsl-bulk-regeneration/blob/master/src/ examples/jobdsl/scm-gradle-gerrit-build.jobDSL
  • 15. Jenkins User Conference San Francisco #jenkinsconf Repeated elements • Job Name • Git URL • Gerrit Trigger Project
  • 16. Jenkins User Conference San Francisco #jenkinsconf Towards Job Factory • Factor out common operations • Parameterize calling Job DSL
  • 17. Jenkins User Conference San Francisco #jenkinsconf Create Utility class • jobdsl.JobUtilities methods • setupGradleGerritJobName() • setupGerritScm() • setupGerritTrigger() • setupGradleBuild()
  • 18. Jenkins User Conference San Francisco #jenkinsconf JobUtilities.groovy • https://github.com/bealeaj1214/jenkins-juc- job-dsl-bulk-regeneration/blob/master/src/ main/groovy/jobdsl/JobUtilities.groovy
  • 19. Jenkins User Conference San Francisco #jenkinsconf generator job DSL • https://github.com/bealeaj1214/jenkins-juc- job-dsl-bulk-regeneration/blob/master/src/ generator/jobdsl/ seed4GradleGerritJobs.jobDSL
  • 20. Jenkins User Conference San Francisco #jenkinsconf Part 2 : System Groovy
  • 21. Jenkins User Conference San Francisco #jenkinsconf Regeneration script import jenkins.model.* ! import hudson.model.* ! def jenkins = jenkins.model.Jenkins.instance def jobGeneratorName='gradle-gerrit-job-generator' def jobGenerator = jenkins.getItem(jobGeneratorName) def projectParamName ='PROJECT_NAME' def projectParamValue=‘sample/java/library' ! if(jobGenerator){ boolean buildQueued = jobGenerator.scheduleBuild( 5, new Cause.UserIdCause(), new ParametersAction( new StringParameterValue(projectParamName, projectParamValue) ) ) }
  • 22. Jenkins User Conference San Francisco #jenkinsconf Regenerate from existing job name import jenkins.model.* ! import hudson.model.* ! def jenkins = jenkins.model.Jenkins.instance def jobGeneratorName='gradle-gerrit-job-generator' def jobGenerator = jenkins.getItem(jobGeneratorName) def projectParamName ='PROJECT_NAME' def jobs = jenkins.getItems() ! def gerritJobs = jobs.findAll { job -> job.name.endsWith('gradle-gerrit') } ! def projectNames =gerritJobs.collect { item -> item.triggers.values().find { it.class.simpleName =='GerritTrigger' }. gerritProjects[0].pattern } ! if(jobGenerator){ projectNames.each { projectName -> boolean buildQueued = jobGenerator.scheduleBuild( 5, new Cause.UserIdCause(), new ParametersAction( new StringParameterValue( projectParamName,projectName) ) ) } }
  • 23. Jenkins User Conference San Francisco #jenkinsconf Summary • Job DSL enables precise control • Define parameterized Job Generator (the piano)
  • 24. Jenkins User Conference San Francisco #jenkinsconf Summary • System Groovy Jobs • automates calling job generator in bulk (piano roll)
  • 25. Jenkins User Conference San Francisco #jenkinsconf Thank You To Our Sponsors Platinum Gold Silver Corporate
  • 26. Jenkins User Conference San Francisco #jenkinsconf Thank You • Source Code at https://github.com/bealeaj1214/ jenkins-juc-job-dsl-bulk-regeneration