Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Automate jenkins job creation (#phpbnl18)
Search
Toni Van de Voorde
January 27, 2018
Technology
1
160
Automate jenkins job creation (#phpbnl18)
Improved version given at phpbnl18
Toni Van de Voorde
January 27, 2018
Tweet
Share
More Decks by Toni Van de Voorde
See All by Toni Van de Voorde
Jenkins Automation
tonivdv
0
340
Automate jenkins job creation
tonivdv
1
1.2k
How to start with docker
tonivdv
1
120
How we use docker for our development environment
tonivdv
5
310
Other Decks in Technology
See All in Technology
ゆめみのアクセシビリティの現在地と今後
ryokatsuse
3
290
エンジニアの生存戦略 〜クラウド潮流の経験から紐解く技術トレンドのメカニズムと乗りこなし方〜
shimy
9
1.9k
運用改善、不都合な真実 / 20240722-ssmjp-kaizen
opelab
17
8.2k
MySQLのロックの種類とその競合
yoku0825
6
1.6k
AWSで”最小権限の原則”を実現するための考え方 /20240722-ssmjp-aws-least-privilege
opelab
10
4.4k
[NIKKEI Tech Talk] KDDI/KAG Scrum & Community for Engineering Training
curanosuke
2
220
[I/O Extended Android 2024] What`s new in Android 2024
kyeongwan
0
220
サーバーレスAPI(API Gateway+Lambda)とNext.jsで 個人ブログを作ろう!
shuntaka
PRO
0
560
スレットハンティングについて知っておきたいこと
hacket
0
130
推薦システムを本番導入する上で一番優先すべきだったこと~NewsPicks記事推薦機能の改善事例を元に~
morinota
0
130
[2024最新版]AWS Control Towerを使ったセキュアなマルチアカウント環境の作り方
hiashisan
0
270
サービス開発を前に進めるために 新米リードエンジニアが 取り組んだこと / Steps Taken by a Novice Lead Engineer to Advance Service Development
nologyance
0
180
Featured
See All Featured
Web Components: a chance to create the future
zenorocha
307
41k
In The Pink: A Labor of Love
frogandcode
139
22k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
34
1.9k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Writing Fast Ruby
sferik
623
60k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
How STYLIGHT went responsive
nonsquared
93
5k
No one is an island. Learnings from fostering a developers community.
thoeni
17
2.8k
StorybookのUI Testing Handbookを読んだ
zakiyama
15
4.9k
Leading Effective Engineering Teams 2024
addyosmani
3
300
Building an army of robots
kneath
301
42k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
16
1.6k
Transcript
Automate jenkins job creation Toni Van de Voorde – CTO
@ Adsdaq.eu
Why Jenkins ? o Free o Open-Source o Customization o
Plugin system o Full control of the system
But o Time needed for configurations / customization
Adsdaq o Microservice oriented o Different techno's o Lot’s of
small feature branches Many jobs to manage !!!
The solution Job DSL Plugin
Job DSL Plugin A groovy-based Domain Specific Language for Jenkins
Jobs
Job DSL Plugin Installation FROM jenkins/jenkins:lts-alpine RUN /usr/local/bin/install-plugins.sh job-dsl
Job DSL Plugin Configuration 1. Create new Freestyle project
Job DSL Plugin Configuration 2. Add SCM
Job DSL Plugin Configuration 3. Add build step
Job DSL Plugin Configuration 4. Configure the build step
Job DSL Plugin Configuration 5. Save and execute the job
Job DSL Plugin Script Security Your first execution failed right
??? o Script Approval o Sandboxing o Disable
Job DSL Plugin Script Security Script Approval
Job DSL Plugin def gitUrl = 'git://github.com/jenkinsci/job-dsl-plugin.git’ job('demo1') { scm
{ git(gitUrl) } triggers { scm('*/15 * * * *') } steps { maven('-e clean test') } } Example demo1.groovy
Job DSL Plugin def gitUrl = 'git://github.com/jenkinsci/job-dsl-plugin.git’ job('demo1') { scm
{ git(gitUrl) } triggers { scm('*/15 * * * *') } steps { maven('-e clean test') } } Example demo1.groovy
Job DSL Plugin def gitUrl = 'git://github.com/jenkinsci/job-dsl-plugin.git’ job('demo1') { scm
{ git(gitUrl) } triggers { scm('*/15 * * * *') } steps { maven('-e clean test') } } Example demo1.groovy
Job DSL Plugin def gitUrl = 'git://github.com/jenkinsci/job-dsl-plugin.git’ job('demo1') { scm
{ git(gitUrl) } triggers { scm('*/15 * * * *') } steps { maven('-e clean test') } } Example demo1.groovy
Job DSL Plugin def gitUrl = 'git://github.com/jenkinsci/job-dsl-plugin.git’ job('demo1') { scm
{ git(gitUrl) } triggers { scm('*/15 * * * *') } steps { maven('-e clean test') } } Example demo1.groovy
Job DSL Plugin Currently supports up to 190 Plugins
Job DSL Plugin Community Driven o > 1000 Pull Requests
o 155 contributors o > 1000 stars
Job DSL Plugin Extend the DSL Heeelp my plugin is
not (yet) supported
Job DSL Plugin Extend the DSL demo2.groovy
Job DSL Plugin Generate Jobs/branch (1) demo3.groovy def gitUrl =
'git://github.com/jenkinsci/job-dsl-plugin.git’ def branches = ['master','dev','hotfix'] branches.each { branch -> job("demo3-${branch}") { scm { git(gitUrl, branch) } } }
Job DSL Plugin Generate Jobs/branch (1) demo3.groovy def gitUrl =
'git://github.com/jenkinsci/job-dsl-plugin.git’ def branches = ['master','dev','hotfix'] branches.each { branch -> job("demo3-${branch}") { scm { git(gitUrl, branch) } } }
Job DSL Plugin Generate Jobs/branch (1) demo3.groovy def gitUrl =
'git://github.com/jenkinsci/job-dsl-plugin.git’ def branches = ['master','dev','hotfix'] branches.each { branch -> job("demo3-${branch}") { scm { git(gitUrl, branch) } } }
Job DSL Plugin Generate Jobs/branch (2) demo4.groovy def project =
'Netflix/asgard’ 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 def jobName = "${project}-${branchName}".replaceAll('/','-') job(jobName) { scm { git("https://github.com/${project}.git", branchName) } } }
Job DSL Plugin Generate Jobs/branch (3) demo5.groovy def project =
'automate-jenkins-job-creation’ def repo = "https://
[email protected]
/tonivdv/${project}.git" Process proc1 = "git ls-remote -h ${repo}".execute() Process proc2 = 'sed s/.*refs\\/heads\\///g'.execute() Process all = proc1 | proc2 all.waitFor() def branches = "${all.in.text}".split('\\n') branches.each { … }
Job DSL Plugin Generate Jobs/branch (4) demo5bis.groovy package utilities public
class GitUtils { public static String[] getRemoteBranches(def repoUrl, def out) { Process proc1 = "git ls-remote -h ${repoUrl}".execute() Process proc2 = 'sed s/.*refs\\/heads\\///g'.execute() Process all = proc1 | proc2 all.waitFor() out.println "### DEBUG: Begin ###" ... out.println "### DEBUG: End ###" def branches = "${all.in.text}".split('\\n') return branches } }
Job DSL Plugin Generate Jobs/branch (5) demo5bis.groovy import utilities.GitUtils def
project = 'automate-jenkins-job-creation’ def repo = https://
[email protected]
/tonivdv/${project}.git def branches = GitUtils.getRemoteBranches(repo, out) folder('demo5bis') branches.each { … }
Job DSL Plugin Conditionals demo6.groovy branches.each { branch -> def
myjob = job(jobName) { .. } if (branch == "master") { myjob.with { steps { maven('-e deploy clean test') } } } else { ... } }
Job DSL Plugin Conditionals demo6.groovy branches.each { branch -> def
myjob = job(jobName) { .. } if (branch == "master") { myjob.with { steps { maven('-e deploy clean test') } } } else { ... } }
Job DSL Plugin Conditionals demo6.groovy branches.each { branch -> def
myjob = job(jobName) { .. } if (branch == "master") { myjob.with { steps { maven('-e deploy clean test') } } } else { ... } }
Job DSL Plugin Many other features o Use any Java/Groovy
libraries o Functions to reuse code o Create Views/Folders/Worflows/…
Job DSL Plugin Tips o Credential Plugin o JobConfigHistory Plugin
o Use the great API Viewer o (https://[jenkins-host]/plugin/job-dsl/api-viewer/index.html) o https://jenkinsci.github.io/job-dsl-plugin/
Job DSL Plugin Tips o Commit your DSL scripts to
SCM o Don’t create jobs manually anymore :p
Job DSL Plugin References o Wiki o https://github.com/jenkinsci/job-dsl-plugin/wiki o API
Viewer o https://jenkinsci.github.io/job-dsl-plugin/ o Presentation demo files o https://github.com/tonivdv/automate-jenkins-job-creation
Automate jenkins job creation Questions?
Automate jenkins job creation Toni Van de Voorde
[email protected]
@tonivdv
www.devexp.eu https://github.com/tonivdv Thank You Join our Team
[email protected]
demo-files: https://git.io/vds08 Rate this talk: https://joind.in/talk/26f3d