Upload
nikita-bugrovsky
View
66
Download
2
Embed Size (px)
Citation preview
Job DSL Plugin for Jenkins CIby Nikita Bugrovsky
Devops Consultant at DevOps Israel
02/18/2015
www.devops.co.il
How Simple is Your Workflow?
or
If Workflow is Complex...Can You remember Details?!
If Workflow is Complex...More fun: You Have to Do It with a Mouse!
If Workflow is Complex...Hidden Configuration
Job DSL Plugin to the Rescue!
GroovyDSL
How to use Job DSL Plugin?
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 {} }
Create free-style project in Jenkins
Add SCM with Job Templates
Add “Process Job DSL Step”
"Build result" page will list the jobs
Test-Project-1Test-Project-2Test-Project-3Test-Project-4Test-Project-5Test-Project-6
Job DSL Plugin: Groovy -> XML -> GUI
job { name "Test_Project" scm { git("[email protected]:YourOrganization/your-repo.git") }}
<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
Job DSL Plugin: Groovy -> XML -> GUI
Configure {} Block
GUI<project> <properties> <class="com.example.Test"> <switch> on </switch> </class> </properties></project>
Configure {} Block
job { name "Test_Project" configure { it / "properties" / "com.example.Test" { "switch"("on") } } }
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)
}
}
}
Single Point of Configuration
evaluate(new File("/path/to/GlobalConfig.groovy"))
job {
name NewName
}
NewName = "Test_Job"
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}"}
}
Viewsjob {
view(type: ListView) {
name('Mcr')
description('This View displays Mcr
jobs')
filterBuildQueue()
filterExecutors()
jobs {
regex('Mcr.+')
}
}}
● SCM to Control Code/Trace Changes● Write/Refactor Jobs via Groovy Code● Save time -> PROFIT!
Job DSL Plugin: Benefits
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