Top Banner
Plugin Development with Gradle and Groovy Daniel Spilker – CoreMedia AG
19

Jenkins Plugin Development With Gradle And Groovy

Aug 14, 2015

Download

Software

Daniel Spilker
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Jenkins Plugin Development With Gradle And Groovy

Plugin Development with Gradle and Groovy

Daniel Spilker – CoreMedia AG

Page 2: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Plugin Development – It‘s Your Choice

• Build Tool– Maven, Gradle, …

• Programming Language– Java, Groovy, Ruby, Python, …

• Testing– JUnit, Spock, …

Page 3: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Plugin Development – It‘s Your Choice

• Build Tool– Maven, Gradle, …

• Programming Language– Java, Groovy, Ruby, Python, …

• Testing– JUnit, Spock, …

Page 4: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Gradle JPI Plugin

Page 5: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Gradle JPI Plugin

• Builds the Jenkins plugin file (HPI / JPI)• Can be combined with other Gradle plugins• Hooks into the standard Gradle tasks• Recommended prerequisites

– Java 7– Gradle 2.3

Page 6: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Example

buildscript { … }

apply plugin: 'org.jenkins-ci.jpi'

group = 'org.jenkins-ci.plugins'version = '0.0.1-SNAPSHOT'description = 'A description of your plugin'

jenkinsPlugin { coreVersion = '1.580' displayName = 'Hello World' url = 'http://wiki.jenkins-ci.org/display/JENKINS/Hello+World' gitHubUrl = 'https://github.com/jenkinsci/hello-world-plugin' developers { … }}

Page 7: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Directory Structure

hello-world-plugin+---build.gradle\---src +---main | +---groovy | \---resources \---test +---groovy \---resources

Page 8: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Gradle Tasks

• gradle server– Start a Jenkins instance with the plugin installed for

manual testing

• gradle jpi– Build the Jenkins plugin file

• gradle publish– Deploy your plugin to the Jenkins Maven repository to

be included in the Update Center

Page 9: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Further Information

• Documentationhttps://wiki.jenkins-ci.org/display/JENKINS/Gradle+JPI+Plugin

• Issue Trackerhttps://issues.jenkins-ci.org/browse/JENKINS/component/16321

• Jenkins Developer Mailing Listhttps://groups.google.com/forum/#!forum/jenkinsci-dev

• Examplehttps://github.com/jenkinsci/job-dsl-plugin

Page 10: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Groovy

Page 11: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Groovy

• All documentation and examples about plugin development with Java also apply to Groovy

• Jenkins comes with Groovy 1.8

Page 12: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Example

class HelloWorldBuilder extends Builder { final String name

@DataBoundConstructor HelloWorldBuilder(String name) { … }

@Override boolean perform(…) { listener.logger.println("Hello, ${name}!") true }}

Page 14: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Spock Framework

Page 15: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Spock Framework

• Spock 0.7 must be used due to Groovy 1.8 constraint• Gradle dependency declaration

dependencies { testCompile 'org.spockframework:spock-core:0.7-groovy-1.8' }

• The Jenkins test harness can be used @RuleJenkinsRule jenkinsRule = new JenkinsRule()

Page 16: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Example

class ExampleSpec extends Specification { @Rule JenkinsRule jenkinsRule = new JenkinsRule()

def 'some example test'() { setup: FreeStyleProject job = jenkinsRule.createFreeStyleProject('seed')

when: FreeStyleBuild freeStyleBuild = job.scheduleBuild2(0).get()

then: freeStyleBuild.result == SUCCESS }}

Page 17: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Further Information

• Documentationhttp://docs.spockframework.org/

• Testing pluginshttps://wiki.jenkins-ci.org/display/JENKINS/Unit+Test

Page 18: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Summary – It‘s Your Choice

• Build Tool– Maven, Gradle, …

• Programming Language– Java, Groovy, Ruby, Python, …

• Views– Jelly, Groovy

• Testing– JUnit, Spock, …

Page 19: Jenkins Plugin Development With Gradle And Groovy

#jenkinsconf

Thank You

Daniel Spilker

[email protected]

@daspilker

We‘re hiring

www.coremedia.com

@CoreMediaMinds