23
Job DSL Plugin for Jenkins CI by Nikita Bugrovsky Devops Consultant at DevOps Israel 02/18/2015 www.devops.co.il

Jenkins Job DSL plugin

Embed Size (px)

Citation preview

Page 1: Jenkins Job DSL plugin

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

How Simple is Your Workflow?

or

Page 3: Jenkins Job DSL plugin

If Workflow is Complex...Can You remember Details?!

Page 4: Jenkins Job DSL plugin

If Workflow is Complex...More fun: You Have to Do It with a Mouse!

Page 5: Jenkins Job DSL plugin

If Workflow is Complex...Hidden Configuration

Page 6: Jenkins Job DSL plugin

Job DSL Plugin to the Rescue!

GroovyDSL

Page 7: Jenkins Job DSL plugin

How to use Job DSL Plugin?

Page 8: Jenkins 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 {} }

Page 9: Jenkins Job DSL plugin

Create free-style project in Jenkins

Page 10: Jenkins Job DSL plugin

Add SCM with Job Templates

Page 11: Jenkins Job DSL plugin

Add “Process Job DSL Step”

Page 12: Jenkins Job DSL plugin

"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

Job DSL Plugin: Groovy -> XML -> GUI

job { name "Test_Project" scm { git("[email protected]:YourOrganization/your-repo.git") }}

Page 14: Jenkins Job DSL plugin

<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

Job DSL Plugin: Groovy -> XML -> GUI

Page 16: Jenkins Job DSL plugin

Configure {} Block

GUI<project> <properties> <class="com.example.Test"> <switch> on </switch> </class> </properties></project>

Page 17: Jenkins Job DSL plugin

Configure {} Block

job { name "Test_Project" configure { it / "properties" / "com.example.Test" { "switch"("on") } } }

Page 18: Jenkins Job DSL plugin

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

Single Point of Configuration

evaluate(new File("/path/to/GlobalConfig.groovy"))

job {

name NewName

}

NewName = "Test_Job"

Page 20: Jenkins Job DSL plugin

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

Viewsjob {

view(type: ListView) {

name('Mcr')

description('This View displays Mcr

jobs')

filterBuildQueue()

filterExecutors()

jobs {

regex('Mcr.+')

}

}}

Page 22: Jenkins Job DSL plugin

● 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

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