Grooving with Jenkins

Information about Grooving with Jenkins

Published on July 18, 2015

Author: AntonWeiss

Source: slideshare.net

Content

1. Jenkins World Tour 2015 Tel Aviv, Israel July 2015 1

2. #jenkinsconf Grooving with the Butler Anton Weiss, (otomato) 2

3. #jenkinsconf About me Ant(on) Weiss DevOps Evangelist&Enabler, CI/CD/ALM Expert now at PrimaryData Inc. [email protected] twitter: @antweiss http://otomato.link3

4. #jenkinsconf 4 GROOVY

5. #jenkinsconf The Groovy Language • Easy to learn and use • Compiles to JVM bytecode • Dynamic, optionally-typed • Fully interoperates with Java • Provides scripting capabilities • Allows DSL authoring • Meta-programming • Functional programming 5

6. #jenkinsconf Hello , groovy world! def sayHello(name) { println("Hello $name!") } def name = 'world' sayHello(name) 6

7. #jenkinsconf Groovy use in Jenkins • Perform Maintenance Tasks • Extend Functionality (instead of writing a full-fledged plugin) • Retrieve Information 7

8. #jenkinsconf Get into the Groove! • Groovy to Manage your Jenkins 8

9. #jenkinsconf Jenkins Script Console 9

10. #jenkinsconf Jenkins Script Console 10 import jenkins.model.* import hudson.plugins.git.* Hudson.instance.items.each() { job -> def SCM = job.getScm() if(SCM instanceof GitSCM ) { def url = SCM.userRemoteConfigs[0].url println url new_url = url.replaceAll(/antweiss/, "otomato") SCM.userRemoteConfigs[0].url = new_url job.save() } }

11. #jenkinsconf Jenkins Script Console • No version control for scripts • Requires manual editing to change values Solution: • Jenkins Scriptler Plugin https://wiki.jenkins- ci.org/display/JENKINS/Scriptler+Plugin 11

12. #jenkinsconf Go on grooving! • Grooving with Parameters! 12

13. #jenkinsconf Groovy for Dynamic Parameters • Retrieve parameter values dynamically: • from Jenkins itself • from external data sources: • e.g: SCM, DB, file system 13

14. #jenkinsconf Groovy for Parameters - Example • Retrieve a list of successful builds of a project: import jenkins.model.* job = Jenkins.instance.getItem(jobname) job.getBuilds().each() { build -> if ( build.result.toString() == "SUCCESS") { println build.number } }14

15. #jenkinsconf Groovy for Dynamic Parameters • Use with: • Dynamic Parameter Plugin (+Scriptler) • Extended Choice Parameter Plugin • Extensible Choice Parameter Plugin 15

16. #jenkinsconf Groovier Yet! • Grooving with Build Steps! 16

17. #jenkinsconf Groovy Build Steps • Jenkins Groovy Plugin • run regular groovy scripts • run “system groovy scripts” : • inside Jenkins master JVM • schedule maintenance scripts • extend functionality: • build.setDescription(build.buildVariables.get(‘VERSION_NUM')) 17

18. #jenkinsconf Go on grooving! • Grooving after Builds! 18

19. #jenkinsconf Groovy Post-Build Plugin • Provides ‘manager’ object • Provides log parser methods: logContains(regexp) getLogMatcher(regexp) - returns a java.util.regex.Matcher • Provides decorator methods: manager.addShortText(“$manager.getEnvVariable('DD_VERSION')}") 19

20. #jenkinsconf Groovy Post-Build Plugin def exit_status = manager.getEnvVariable("EXIT_FLAG") def SETUP_NAME=manager.getEnvVariable("name") switch (exit_status) { case "0": manager.buildSuccess() break case "9": manager.buildUnstable() manager.addBadge("delete.gif", "release setup", “http://my.server.com:8080/view/integration/job/drms-release- setup/parambuild/?name=$SETUP_NAME”) manager.createSummary("orange-square.png").appendText("<b>Setup name:</b> $SETUP_NAME", false, false, false, "grey") break default: manager.buildFailure() } 20

21. #jenkinsconf Groovy Emails • Using Groovy with Email-ext plugin 21 +

22. #jenkinsconf Groovy Emails • In ‘Recipient List’ field: • ${SCRIPT, script=“upstream_committers.groovy”} • For email templates: • ${SCRIPT, template="groovy-html1.template"} 22

23. #jenkinsconf Still want a plugin? • The Groovy Way to Write Jenkins Plugins • by Shiran Rubin (jfrog) 23

24. #jenkinsconf Footer Divider Slide Thanks and Be Groovy!!! 24

#jenkinsconf presentations

Related presentations


Other presentations created by AntonWeiss

Ninja, Choose Your Weapon!
29. 03. 2015
0 views

Ninja, Choose Your Weapon!

Docker, Jenkins, Docker
16. 07. 2017
0 views

Docker, Jenkins, Docker

A Deeper Look at Cargo
13. 12. 2018
0 views

A Deeper Look at Cargo