jenkins jobdsl - configuration as code

26
November 2016 Jenkins Job DSL Configuration as Code

Upload: tomasnorre

Post on 22-Jan-2017

119 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Jenkins JobDSL - Configuration as code

November 2016

Jenkins Job DSL Configuration as Code

Page 2: Jenkins JobDSL - Configuration as code

November 2016

• Introduction

• Jenkins

• How to create jobs/views

• Job DSL

• Questions

Page 3: Jenkins JobDSL - Configuration as code

November 2016

Tomas Norre Mikkelsen

• AOE GmbH - June 2013

• DevOps/Automation

• TYPO3.org, Crawler

• Golf, #t3runners

• @tomasnorre

Page 4: Jenkins JobDSL - Configuration as code

November 2016

We are the champions

- Team FourSquare

Page 5: Jenkins JobDSL - Configuration as code

November 2016

I have been running marathons - but still I consider myself being lazy!

Page 6: Jenkins JobDSL - Configuration as code

November 2016

What is Jenkins?

Page 7: Jenkins JobDSL - Configuration as code

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

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

November 2016

Create a Jenkins job

Page 10: Jenkins JobDSL - Configuration as code

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 &quot;Welcome to T3EE16 - Jenkins JobDSL&quot;</command> </hudson.tasks.Shell> </builders> <publishers/> <buildWrappers/> </project>

Every configuration is XML

Page 11: Jenkins JobDSL - Configuration as code

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

November 2016

Job DSL

• Domain Specific Language • Groovy • Can be extend with configure blocks

Page 13: Jenkins JobDSL - Configuration as code

November 2016

File structure

Page 14: Jenkins JobDSL - Configuration as code

November 2016

job('t3ee_groovy') { steps { shell(''' #!/bin/sh echo "Welcome to T3EE16 - Jenkins JobDSL" ''') } }

Groove Job

Page 15: Jenkins JobDSL - Configuration as code

November 2016

Play ground

Page 16: Jenkins JobDSL - Configuration as code

November 2016

How to setup Jenkins JobDSL

• install Job DSL plugin • Seeder job

Page 17: Jenkins JobDSL - Configuration as code

November 2016

Seeder Job

Page 18: Jenkins JobDSL - Configuration as code

November 2016

Shared configuration

Page 19: Jenkins JobDSL - Configuration as code

November 2016

Looping for environments

Page 20: Jenkins JobDSL - Configuration as code

November 2016

Setting up views

Page 21: Jenkins JobDSL - Configuration as code

November 2016

How to test your jobs

Page 22: Jenkins JobDSL - Configuration as code

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

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

November 2016

Developers want to write code, so let them do what they love!

Page 25: Jenkins JobDSL - Configuration as code

November 2016

Questions?@tomasnorre [email protected]

Page 26: Jenkins JobDSL - Configuration as code

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