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

Jenkins Plugin Development With Gradle And Groovy

Embed Size (px)

Citation preview

Plugin Development with Gradle and Groovy

Daniel Spilker – CoreMedia AG

#jenkinsconf

Plugin Development – It‘s Your Choice

• Build Tool– Maven, Gradle, …

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

• Testing– JUnit, Spock, …

#jenkinsconf

Plugin Development – It‘s Your Choice

• Build Tool– Maven, Gradle, …

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

• Testing– JUnit, Spock, …

#jenkinsconf

Gradle JPI Plugin

#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

#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 { … }}

#jenkinsconf

Directory Structure

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

#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

#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

#jenkinsconf

Groovy

#jenkinsconf

Groovy

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

• Jenkins comes with Groovy 1.8

#jenkinsconf

Example

class HelloWorldBuilder extends Builder { final String name

@DataBoundConstructor HelloWorldBuilder(String name) { … }

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

#jenkinsconf

Spock Framework

#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()

#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 }}

#jenkinsconf

Further Information

• Documentationhttp://docs.spockframework.org/

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

#jenkinsconf

Summary – It‘s Your Choice

• Build Tool– Maven, Gradle, …

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

• Views– Jelly, Groovy

• Testing– JUnit, Spock, …

#jenkinsconf

Thank You

Daniel Spilker

[email protected]

@daspilker

We‘re hiring

www.coremedia.com

@CoreMediaMinds