Jenkins JobDSL - Configuration as code
-
Upload
tomasnorre -
Category
Software
-
view
114 -
download
1
Transcript of Jenkins JobDSL - Configuration as code
![Page 1: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/1.jpg)
November 2016
Jenkins Job DSL Configuration as Code
![Page 2: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/2.jpg)
November 2016
• Introduction
• Jenkins
• How to create jobs/views
• Job DSL
• Questions
![Page 3: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/3.jpg)
November 2016
Tomas Norre Mikkelsen
• AOE GmbH - June 2013
• DevOps/Automation
• TYPO3.org, Crawler
• Golf, #t3runners
• @tomasnorre
![Page 4: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/4.jpg)
November 2016
We are the champions
- Team FourSquare
![Page 5: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/5.jpg)
November 2016
I have been running marathons - but still I consider myself being lazy!
![Page 6: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/6.jpg)
November 2016
What is Jenkins?
![Page 7: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/7.jpg)
November 2016
The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project. - https://jenkins.io/
![Page 8: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/8.jpg)
November 2016
• Run Unit tests • Build docker images • Build artifacts • Deploy website/applications • Publish TER Extensions on Git-tag • etc.
What can we use Jenkins for
![Page 9: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/9.jpg)
November 2016
Create a Jenkins job
![Page 10: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/10.jpg)
November 2016
<?xml version='1.0' encoding='UTF-8'?> <project> <description></description> <keepDependencies>false</keepDependencies> <properties> <hudson.plugins.buildblocker.BuildBlockerProperty plugin="[email protected]"> <useBuildBlocker>false</useBuildBlocker> <blockLevel>GLOBAL</blockLevel> <scanQueueFor>DISABLED</scanQueueFor> <blockingJobs></blockingJobs> </hudson.plugins.buildblocker.BuildBlockerProperty> <com.sonyericsson.rebuild.RebuildSettings plugin="[email protected]"> <autoRebuild>false</autoRebuild> <rebuildDisabled>false</rebuildDisabled> </com.sonyericsson.rebuild.RebuildSettings> </properties> <scm class="hudson.scm.NullSCM"/> <canRoam>true</canRoam> <disabled>false</disabled> <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <triggers/> <concurrentBuild>false</concurrentBuild> <builders> <hudson.tasks.Shell> <command>#!/bin/sh
echo "Welcome to T3EE16 - Jenkins JobDSL"</command> </hudson.tasks.Shell> </builders> <publishers/> <buildWrappers/> </project>
Every configuration is XML
![Page 11: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/11.jpg)
November 2016
Challenges
• Copying jobs • Adjusting same setting multiple times • UI can be slow • Fields hidden under advanced button
![Page 12: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/12.jpg)
November 2016
Job DSL
• Domain Specific Language • Groovy • Can be extend with configure blocks
![Page 13: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/13.jpg)
November 2016
File structure
![Page 14: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/14.jpg)
November 2016
job('t3ee_groovy') { steps { shell(''' #!/bin/sh echo "Welcome to T3EE16 - Jenkins JobDSL" ''') } }
Groove Job
![Page 15: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/15.jpg)
November 2016
Play ground
![Page 16: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/16.jpg)
November 2016
How to setup Jenkins JobDSL
• install Job DSL plugin • Seeder job
![Page 17: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/17.jpg)
November 2016
Seeder Job
![Page 18: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/18.jpg)
November 2016
Shared configuration
![Page 19: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/19.jpg)
November 2016
Looping for environments
![Page 20: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/20.jpg)
November 2016
Setting up views
![Page 21: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/21.jpg)
November 2016
How to test your jobs
![Page 22: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/22.jpg)
November 2016
Pros & Cons
• Version Control • More readable • Change shared configurations • Test locally • Review
• Not all plugins are supported • Learning curve
![Page 23: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/23.jpg)
November 2016
Best practice
• Start converting few jobs • All jobs goes to version control • Trigger seed job on SCM changes • Don’t commit credentials • Think about design, refactor, streamline etc.
it’s code treat it like code.
![Page 24: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/24.jpg)
November 2016
Developers want to write code, so let them do what they love!
![Page 26: Jenkins JobDSL - Configuration as code](https://reader031.fdocuments.us/reader031/viewer/2022022202/5883ebf51a28ab34428b52a1/html5/thumbnails/26.jpg)
November 2016
• https://jenkinsci.github.io/job-dsl-plugin/ - Documentation
• http://job-dsl.herokuapp.com/ - Play Ground
• http://www.groovy-lang.org/ - Groove Website
• https://github.com/tomasnorre/t3ee16_jenkins - Example Repository
Links