Jenkins Job DSL plugin
-
Upload
nikita-bugrovsky -
Category
Technology
-
view
67 -
download
2
Transcript of Jenkins Job DSL plugin
![Page 1: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/1.jpg)
Job DSL Plugin for Jenkins CIby Nikita Bugrovsky
Devops Consultant at DevOps Israel
02/18/2015
www.devops.co.il
![Page 2: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/2.jpg)
How Simple is Your Workflow?
or
![Page 3: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/3.jpg)
If Workflow is Complex...Can You remember Details?!
![Page 4: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/4.jpg)
If Workflow is Complex...More fun: You Have to Do It with a Mouse!
![Page 5: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/5.jpg)
If Workflow is Complex...Hidden Configuration
![Page 6: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/6.jpg)
Job DSL Plugin to the Rescue!
GroovyDSL
![Page 7: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/7.jpg)
How to use Job DSL Plugin?
![Page 8: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/8.jpg)
Create templates of the jobsjob {
name "Some_Name" displayName "Some display name" customWorspace scm {} parameters{} wrappers{} // build environment configuration steps{} publishers{} // post compilation steps configure {} }
![Page 9: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/9.jpg)
Create free-style project in Jenkins
![Page 10: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/10.jpg)
Add SCM with Job Templates
![Page 11: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/11.jpg)
Add “Process Job DSL Step”
![Page 12: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/12.jpg)
"Build result" page will list the jobs
Test-Project-1Test-Project-2Test-Project-3Test-Project-4Test-Project-5Test-Project-6
![Page 13: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/13.jpg)
Job DSL Plugin: Groovy -> XML -> GUI
job { name "Test_Project" scm { git("[email protected]:YourOrganization/your-repo.git") }}
![Page 14: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/14.jpg)
<project> <scm class="hudson.plugins.git.GitSCM" plugin="[email protected]"> <userRemoteConfigs> <hudson.plugins.git.UserRemoteConfig> <url> [email protected]:YourOrg/your-repo.git </url> </hudson.plugins.git.UserRemoteConfig> </userRemoteConfigs> <branches> <hudson.plugins.git.BranchSpec> <name>*/master</name> </hudson.plugins.git.BranchSpec> </branches> </scm></project>
Job DSL Plugin: Groovy -> XML -> GUI
![Page 15: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/15.jpg)
Job DSL Plugin: Groovy -> XML -> GUI
![Page 16: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/16.jpg)
Configure {} Block
GUI<project> <properties> <class="com.example.Test"> <switch> on </switch> </class> </properties></project>
![Page 17: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/17.jpg)
Configure {} Block
job { name "Test_Project" configure { it / "properties" / "com.example.Test" { "switch"("on") } } }
![Page 18: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/18.jpg)
JsonSlurperdef project = 'YourProject/build-project'
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)
}
}
}
![Page 19: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/19.jpg)
Single Point of Configuration
evaluate(new File("/path/to/GlobalConfig.groovy"))
job {
name NewName
}
NewName = "Test_Job"
![Page 20: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/20.jpg)
Iterate Over Job Names
def job_prefixes = ["CI", "NB"]// Configure the jobs for each job preffix - "CI", "NB"job_prefixes.each() {
def job_prefix = itjob {
name "${job_prefix}"}
}
![Page 21: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/21.jpg)
Viewsjob {
view(type: ListView) {
name('Mcr')
description('This View displays Mcr
jobs')
filterBuildQueue()
filterExecutors()
jobs {
regex('Mcr.+')
}
}}
![Page 22: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/22.jpg)
● SCM to Control Code/Trace Changes● Write/Refactor Jobs via Groovy Code● Save time -> PROFIT!
Job DSL Plugin: Benefits
![Page 23: Jenkins Job DSL plugin](https://reader034.fdocuments.in/reader034/viewer/2022042516/55d2d768bb61eb412d8b45bf/html5/thumbnails/23.jpg)
Useful links
● DSL to XML online https://job-dsl.herokuapp.com/
● Job DSL Wiki https://github.com/jenkinsci/job-dsl-plugin/wiki
● Groovy Docs http://groovy.codehaus.org/Documentation