Job DSL Plugin for Jenkins
-
Upload
niels-bech-nielsen -
Category
Software
-
view
297 -
download
12
description
Transcript of Job DSL Plugin for Jenkins
![Page 2: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/2.jpg)
ServicesPublic ServicesProfessional ServicesProjects & DevOpsApplication ManagementArchitectureSecurityOpen Source
![Page 3: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/3.jpg)
3
>sed –i s/bug/feature/g *>git commit -a -m ”Fixed”
HappyCustomer
Continuous Integration X–Mas Pipeline
One Button Deployment
Circle of Software Development
![Page 4: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/4.jpg)
4
?
How do you manage changes in your Pipelines?
X
![Page 5: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/5.jpg)
5
Proj
ect A
• Commit• Regression
tests• Integration
Tests• Q+A
• Deployment
Proj
ect B • Commit
• Nightly Release
• Regression tests
• Q+A
• Deployment
Proj
ect C • Commit
• Integration Tests
• Test Deploy• Acceptance
Tests• Q+A
• Deployment
How do you manage changes in your Pipelines?
![Page 6: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/6.jpg)
6
Options include
• Template Project Plugin• Job Generator Plugin• Parameterized Build Plugin
• … (your own homegrown solution or click-edit)
• Job DSL Plugin
![Page 7: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/7.jpg)
7
def project = 'nbn/griffon-maven-plugin'def branchApi = new URL("https://api.github.com/repos/${project}/branches")def branches = new groovy.json.JsonSlurper().parse(branchApi.newReader())
branches.each { def branchName = it.name job { name "${project}-${branchName}".replaceAll('/','-') scm { git("git://github.com/${project}.git", branchName) } steps { maven("test -Dproject.name=${project}/${branchName} ") } }}
Configuration as Code
• Treat your configuration as CodeVersionedSimplifiedDRY
• Job DSL provide a simple, intuitive Groovy DSL to create Jenkins jobs from scripts
Generate all your jobs from a ’seed’ jobAbstract utility functionsSupports all Jenkins plugins through extension
• NO MORE HTML EDITING
![Page 8: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/8.jpg)
8
Photo Credits
• Nerd – Stephanie Klocke• Happy Customer – VeganSoldier• Fujii and Pri – Marcelo Jorge Vieria• Jenkins without broken builds – Henrique Imbertti Jr• Antares Rocket Test Launch – NASA• Launch Button – Steven Depolo• Etsy Jenkins Cluster – Noah Sussman
![Page 9: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/9.jpg)
9
Simple DSL example
def project = 'nbn/griffon-maven-plugin'def branchApi = new URL("https://api.github.com/repos/${project}/branches")def branches = new groovy.json.JsonSlurper().parse(branchApi.newReader())
branches.each { def branchName = it.name job { name "${project}-${branchName}".replaceAll('/','-') scm { git("git://github.com/${project}.git", branchName) } steps { maven("test -Dproject.name=${project}/${branchName} ") } }} https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-DSL-Commands
![Page 10: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/10.jpg)
10
Utility Methods in Common Files
import javaposse.jobdsl.dsl.Job
public class Common { static def addNightlyScmTrigger(Job job) { job.with { triggers { scm('H 23 * * *')} } } }
import Common
def job = …
Common.addNightlyScmTrigger(job)
![Page 11: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/11.jpg)
11
Extending the project with custom XML
${project}/config.xml
![Page 12: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/12.jpg)
12
Configure Project Node
job { name "${project}-${branchName}".replaceAll('/','-') scm { git("git://github.com/${project}.git", branchName) } steps { maven("test -Dproject.name=${project}/${branchName} ") }
configure { projectNode -> projectNode / publishers << "hudson.plugins.jdepend.JDependRecorder" { configuredJDependFile() } }
![Page 13: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/13.jpg)
13
Monkey Patch
• Add new features to job dsl entitiesFind existing ContextNode and add new method
Import JDependContext
job { name "${project}-${branchName}".replaceAll('/','-') scm { git("git://github.com/${project}.git", branchName) } publishers { jdepend() // Takes an optional string arg } }
![Page 14: Job DSL Plugin for Jenkins](https://reader033.fdocuments.us/reader033/viewer/2022061209/548db73cb479598e6a8b47b3/html5/thumbnails/14.jpg)
14
Monkey Patching in a Static Block
import javaposse.jobdsl.dsl.helpers.publisher.*
public class JDependContext { static { PublisherContext.metaClass.jdepend = { String preGeneratedJDependFile = '' -> publisherNodes << new NodeBuilder(). "hudson.plugins.jdepend.JDependRecorder" { configuredJDependFile(preGeneratedJDependFile) } } }