JUC Europe 2015: Configuration as Code: The Job DSL Plugin

27 %
73 %
Information about JUC Europe 2015: Configuration as Code: The Job DSL Plugin

Published on June 23, 2016

Author: cloudbees

Source: slideshare.net

1. Configuration as Code: The Job DSL Plugin Daniel Spilker – CoreMedia AG

2. #jenkinsconf Current Situation •  No single job that builds everything •  Each branch needs its own pipeline •  Every team has their own jobs

3. #jenkinsconf Problem •  Lots of copy&paste •  Editing in HTML text areas •  Settings hidden behind Advanced button •  Working with the UI can be slow

4. #jenkinsconf Configuration As Code •  Create new pipelines quickly •  Refactor jobs •  Trace changes •  Work with your favorite tool set

5. #jenkinsconf There Is A Plugin For That •  Template Project Plugin •  Job Generator Plugin •  Literate Plugin •  JobConfigHistory Plugin •  Workflow Plugin •  Job DSL Plugin •  … Open Icon Library / CC BY 3.0

6. #jenkinsconf Job DSL Language

7. #jenkinsconf Job DSL Language job('job-dsl-plugin') { scm { github('jenkinsci/job-dsl-plugin') } steps { gradle('clean build') } publishers { archiveArtifacts('**/job-dsl.hpi') } }

8. #jenkinsconf Job DSL Language job('job-dsl-plugin') { scm { github('jenkinsci/job-dsl-plugin') } steps { gradle('clean build') } publishers { archiveArtifacts('**/job-dsl.hpi') } }

9. #jenkinsconf Job DSL Language job('job-dsl-plugin') { scm { github('jenkinsci/job-dsl-plugin') } steps { gradle('clean build') } publishers { archiveArtifacts('**/job-dsl.hpi') } }

10. #jenkinsconf Job DSL Language job('job-dsl-plugin') { scm { github('jenkinsci/job-dsl-plugin') } steps { gradle('clean build') } publishers { archiveArtifacts('**/job-dsl.hpi') } }

11. #jenkinsconf Job DSL Plugin

12. #jenkinsconf Job DSL Plugin •  Install Job DSL Plugin •  Create free-style project •  Add “Source Code Management” •  Add “Process Job DSLs” build step •  Configure scripts •  Run job

13. #jenkinsconf Job DSL Plugin •  Install Job DSL Plugin •  Create free-style project •  Add “Source Code Management” •  Add “Process Job DSLs” build step •  Configure scripts •  Run job

14. #jenkinsconf Job DSL Plugin •  Install Job DSL Plugin •  Create free-style project •  Add “Source Code Management” •  Add “Process Job DSLs” build step •  Configure scripts •  Run job

15. #jenkinsconf Job DSL Plugin •  Install Job DSL Plugin •  Create free-style project •  Add “Source Code Management” •  Add “Process Job DSLs” build step •  Configure scripts •  Run job

16. #jenkinsconf Job DSL Plugin •  Install Job DSL Plugin •  Create free-style project •  Add “Source Code Management” •  Add “Process Job DSLs” build step •  Configure scripts •  Run job

17. #jenkinsconf Job DSL Plugin •  Install Job DSL Plugin •  Create free-style project •  Add “Source Code Management” •  Add “Process Job DSLs” build step •  Configure scripts •  Run job

18. #jenkinsconf Batteries Included 125 plugins supported by the DSL

19. #jenkinsconf Batteries Included EnvInject Groovy Copy Artifact Git Subversion Folders Extra Columns StashNotifier Gradle Build Pipeline Workspace Cleanup GitHub Pull Request Builder GitHub JaCoCoRelease Build Flow Robot Framework Tool Environment Conditional BuildStep Throttle Concurrent Builds Associated Files Workflow Emma Xvnc AnsiColor Timestamper Text-Finder Job DSL Perforce Ant Maven Project

20. #jenkinsconf Batteries Included Checkstyle Categorized Jobs View Build-timeout Config File Provider Golang Delivery Pipeline HipChat Naginator Jabber NestedViews HTML Publisher NodeJS Flowdock Credentials Binding Plot RunDeck Rake Powershell SBT xUnit xvfb Warnings SonarvSphere Cloud RVM Port Allocator Sectioned View SSH Agent Build Monitor Claim Email-ext Findbugs Grails Javadoc Multijob

21. #jenkinsconf Community Driven >65 contributors ~500 pull requests

22. #jenkinsconf Extending The DSL

23. #jenkinsconf Extending The DSL

24. #jenkinsconf Extending The DSL

25. #jenkinsconf Extending The DSL job('example') { ... configure { project -> project / buildWrappers << EnvInjectPasswordWrapper { injectGlobalPasswords(true) } } }

26. #jenkinsconf Everything is Groovy

27. #jenkinsconf Everything is Groovy def branches = ['master', 'feature-a'] branches.each { branch -> job("jenkins-${branch}") { scm { github('jenkinsci/jenkins', branch) } … } }

28. #jenkinsconf Using Libraries •  Any Java / Groovy library (JARs) can be used •  Download and dependency resolution must be handled before running the Job DSL build step •  Anything can be used to download the JARs –  Build tools like Gradle –  Repository Connector Plugin –  Shell script with curl or wget

29. #jenkinsconf Using Libraries import org.kohsuke.github.GitHub def gitHub = GitHub.connect() def repo = gitHub.getRepository('jenkinsci/jenkins') repo.branches.keys.each { branch -> job("jenkins-${branch}") { … } }

30. #jenkinsconf Using Libraries – Gradle Example repositories { jcenter() } configurations { libs } dependencies { libs 'org.kohsuke:github-api:1.50' } task libs(type: Copy) { into 'libs' from configurations.libs }

31. #jenkinsconf Using Libraries – Gradle Example

32. #jenkinsconf Using Functions def createMavenJob(def jobFactory, def name) { jobFactory.mavenJob(name) { goals('clean verify') jdk('Java 7 latest') mavenInstallation('Maven 3.2.5') runHeadless(true) archivingDisabled(true) publishers { sonar() } } }

33. #jenkinsconf Using Functions def createMavenJob(def jobFactory, def name) { … } def jobA = createMavenJob(this, 'project-a') def jobB = createMavenJob(this, 'project-b')

34. #jenkinsconf Using Functions def createMavenJob(def jobFactory, def name) { … } def jobA = createMavenJob(this, 'project-a') def jobB = createMavenJob(this, 'project-b') jobB.with { scm { github('example-corp/project-a') } }

35. #jenkinsconf IDE Support

36. #jenkinsconf IDE Support •  IntelliJ IDEA only •  Use a Gradle build file for configuration apply plugin: 'groovy' sourceSets { … } repositories { … } dependencies { compile 'org.jenkins-ci.plugins:job-dsl-core:1.34' }

37. #jenkinsconf Syntax Highlighting

38. #jenkinsconf Parameter Information

39. #jenkinsconf Documentation

40. #jenkinsconf Using Credentials

41. #jenkinsconf Do not put plain text credentials in a DSL script

42. #jenkinsconf Credentials Plugin •  Use the Credentials Plugin for managing credentials •  The essentials plugins can consume these credentials (Git, Subversion, …) •  Use the Credentials Binding Plugin to map credentials to environment variables

43. #jenkinsconf Using Credentials job('example') { scm { git { remote { github('example-corp/example') credentials('example-corp-github') } } } }

44. #jenkinsconf The DSL In Depth

45. #jenkinsconf Supported Project Types // https://wiki.jenkins-ci.org/display/JENKINS/Maven+Project+Plugin mavenJob(…) { … } // https://wiki.jenkins-ci.org/display/JENKINS/Matrix+Project+Plugin matrixJob(…) { … } // https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin multiJob(…) { … } // https://wiki.jenkins-ci.org/display/JENKINS/Workflow+Plugin workflowJob(…) { … } // https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin buildFlowJob(…) { … }

46. #jenkinsconf Workflow Job Example workflowJob('my-workflow') { definition { cps { script(readFileFromWorkspace('my-workflow.groovy')) sandbox() } } }

47. #jenkinsconf Reading Files workflowJob('my-workflow') { definition { cps { script(readFileFromWorkspace('my-workflow.groovy')) sandbox() } } }

48. #jenkinsconf Extending The DSL – Project Types

49. #jenkinsconf Extending The DSL – Project Types job('multi-branch') { configure { project -> project.name = 'freestyle-multi-branch-project' … } }

50. #jenkinsconf Creating Views listView('project-a') { jobs { regex('project-a-.+') } columns { status() weather() name() } }

51. #jenkinsconf Supported View Types sectionedView(…) { … } nestedView(…) { … } deliveryPipelineView(…) { … } buildPipelineView(…) { … } buildMonitorView(…) { … } categorizedJobsView(…) { … }

52. #jenkinsconf Using Folders folder('team-a') job('team-a/compile') { ... } https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Folders+Plugin

53. #jenkinsconf Best Practices

54. #jenkinsconf Best Practices •  Start by converting a few jobs •  Create new jobs from DSL scripts •  Gradually convert all jobs to DSL scripts

55. #jenkinsconf Best Practices •  Commit your DSL scripts to SCM •  Do not put plain text credentials in DSL scripts •  Use Groovy code to avoid repetition

56. #jenkinsconf Further Information •  Documentation https://github.com/jenkinsci/job-dsl-plugin/wiki •  Mailing List https://groups.google.com/forum/?fromgroups#!forum/job-dsl-plugin •  Examples https://github.com/sheehan/job-dsl-gradle-example •  Playground http://job-dsl.herokuapp.com/

57. #jenkinsconf Questions?

58. #jenkinsconf Thank You Daniel Spilker daniel.spilker@coremedia.com @daspilker We‘re hiring www.coremedia.com @CoreMediaMinds

#jenkinsconf presentations

Add a comment

Comments

Jorja | 20/07/16
I have exactly what info I want. Check, please. Wait, it's free? Awmseoe!

Related pages

JUC Europe 2015 - Configuration as Code: The Job DSL ...

Learn how to practice configuration as code by using the Job DSL plugin for Jenkins. Find out how to organize Job DSL scripts and apply code ...
Read more

Configuration as Code: The Job DSL Plugin - CloudBees

#jenkinsconf Configuration As Code • Create new pipelines quickly • Refactor jobs • Trace changes • Work with your favorite tool set
Read more

Configuration as Code: The Job DSL Plugin | CloudBees

... presented the DSL plugin and showed how the Configuration as a Code Approach can simplify ... JUC Europe: "From Virtual ... Configuration as Code: The ...
Read more

Job DSL Plugin - Jenkins - Jenkins Wiki

I see the Job DSL plug is updated to work with a lot of different plugins. I didn't see the "Hidden Parameter" plugin on the list. Could that be added in ...
Read more

JUC Europe 2015 - Making Plugins That Are ... - YouTube

By: by Ton Schoots, Black Duck Software, Inc. Making Plugins That Are Enterprise Ready by Ton Schoots The speaker has delivered four enterprise ...
Read more

JUC Speaker Blog Series: Andrew Bayer, JUC Europe

JUC Speaker Blog Series: Andrew Bayer, JUC Europe ... London, there’s JUC Europe 2015, with talks covering things like the fantastic Job DSL plugin, ...
Read more

Talks and Blog Posts · jenkinsci/job-dsl-plugin Wiki · GitHub

job-dsl-plugin - A Groovy DSL for ... jenkinsci / job-dsl-plugin forked from JavaPosseRoundup/job-dsl-plugin. ... June 2015 JUC Europe: Configuration as ...
Read more

JUC Speaker Blog Series: Damien Coraboeuf, JUC Europe

JUC Speaker Blog Series: Damien Coraboeuf, JUC Europe ... When we thought about using the Job DSL ... The pipeline library code reads the “shopping ...
Read more