Presentation on how to chat with PDF using ChatGPT code interpreter
Writing a Jenkins / Hudson plugin
1. Writing a Hudson / Jenkins plugin
Anthony Dahanne @ EclipseCon NA 2014, March 19th
2. EclipseCon NA 2014 — Writing a Hudson / Jenkins pluginConfoo 2013
About me …
"2
§ Software Engineer at Terracotta
– Working on EhCache management REST API and
webapp (aka Terracotta Management Console, TMC)
– Strong interest in CI & build tools (Maven, Jenkins,
Hudson, Nexus plugins author)
– Android developer when time permits ...
3. EclipseCon NA 2014 — Writing a Hudson / Jenkins pluginConfoo 2013
Terracotta
"3
§ Founded 2003 in San Francisco, CA
§ Joined Software AG in 2011
§ Present in India, Europe
and pretty much all over the globe!
§ The company behind :
4. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Agenda
§ Jenkins / Hudson ? Quick intro
§ Do I need to create a plugin ?
§ Let’s build a plugin !
§ How to (integration) test this plugin
§ Share the plugin with the community
"4
6. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Jenkins / Hudson ?
§ Hudson is an open source Continuous Integration
(CI) tool created in 2005 by Kohsuke Kawaguchi
§ Became really popular from 2008
§ The project split in November 2010
§ Hudson moved to the Eclipse Foundation in May
2011
§ Still the most popular CI tool(s) in 2014
"6
7. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
InfoQ CI popularity results
"7
HudsonJenkins
8. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Jenkins / Hudson few differences (figures)
§ 5000 commits
§ 325 contributors
§ 70 000 installs (9/13)
§ 889 plugins
"8
§ 1230 commits
§ 15 contributors
§ 65 000 downloads (9/13)
§ 379 plugins
Since September 2011
9. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Jenkins / Hudson few differences (features)
§ plugins hot install
§ write views in Groovy
§ UI improvements
"9
§ maven3 plugin
§ cascading project settings
§ Eclipse IP clean
§ team concept
Since September 2011
11. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Do we need yet another plugin ?
§ 100’s of existing plugins in the update centers !
§ Customized reports / trigger a build
– CLI
– Remote API
§ Groovy plugin(s)
– Allow you to run a groovy script during build or post build
"11
12. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Hudson / Jenkins CLI
§ You can list jobs, start them, delete them (same
applies for nodes)
!
§ $ java -jar hudson-cli.jar -s http://localhost:8080/ list-jobs
§ $ java -jar hudson-cli.jar -s http://localhost:8080/ build
ehcache-jcache_master
!
§ Perfect for command line scripts !
"12
13. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Remote API
§ Take any Hudson / Jenkins url, add
– /api/xml : xml representation of your view
– /api/json : json representation of your view
§ Depth to control the level of detail
– http://ci.jruby.org/api/xml?depth=1
§ Tree to specify what you want
– http://ci.jruby.org/api/xml?
tree=jobs[displayName,lastBuild[result]]
§ Enjoy powerful xpath filters (with /api/xml only)
– http://ci.jruby.org/api/xml?
tree=jobs[displayName,lastBuild[result]]&exclude=hudson/
job[lastBuild[result=%27SUCCESS%27]]
"13
14. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Groovy plugin(s)
§ Allow you to run a groovy script during build or post build
– EnvInject Plugin : inject System env. variable to your
build
– Groovy Postbuild plugin : execute a groovy script in the
Jenkins VM
§ Usage of those plugins is powerful (dangerous?), they
usually have access to the Jenkins API and runtime
"14
16. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Let’s write a plugin !
§ hpi:create to bootstrap the creation
$ mvn org.eclipse.hudson.tools:maven-hpi-plugin:create
§ hpi:run to run it in a fresh container
$ mvn package org.eclipse.hudson.tools:maven-hpi-plugin:run
"16
17. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
What got created
"17
Diagram copied from the book Hudson Continuous Integration in Practice
19. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Extensions points : dashboard
"19
ListView ListViewColumnRootAction
PageDecorator
20. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Extensions points : job view
"20
TransientProjectActionFactory
BuildBadgeAction
21. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
UI Descriptor and Jelly views
"21
Use the class name for your resources folder
Plugin description (appears in the update center)
help caption for the field “name”
UI configuration for the system configuration page
UI configuration for the Job configuration page
22. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Variables accessible from Jelly
"22
§ app : maps to Hudson.getInstance()
§ app.getUrl() maps to Hudson.getInstance().getUrl()
§ it : maps to the UI element rendered by Jelly
§ it.name maps to HelloWorldBuilder.getName()
§ h : maps to the Functions class
§ h.jsStringEscape() maps to Functions.jsStringEscape()
24. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Write integration tests
§ Write a class that extends HudsonTestCase
§ Benefit from its helper methods to configure
Hudson :
– createFreeStyleProject() and friends
– assertBuildStatus() and others
– WebClient.getPage() and WebAssert.assertElementPresent()
§ or inject existing configuration with @LocalData
"24
25. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Write integration tests (local data layout)
"25
Use the class name for your resources folder
26. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Run your integration tests
§ From your IDE, Run as… / Debug as …
§ With Maven, the usual
– $ mvn clean test (-Dtest=org.my.Test)
§ A friend’s advice : fork your VM when running a test suite
§ Add in your pom :
"26
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<configuration>
<!-- make sure each test spawns a different vm -->
<forkMode>always</forkMode>
</configuration>
</plugin>
</plugins>
</build>
28. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Share your Jenkins plugin with the community
§ Test it and target the lowest API level possible
§ Add Maven metadata
§ Ask jenkinsci-dev@googlegroups.com to create a
github repo to host your plugin
§ Create a wiki page on https://wiki.jenkins-ci.org/
display/JENKINS/Home
§ Release your plugin with maven to the Jenkins repo
§ Built on https://jenkins.ci.cloudbees.com/job/plugins/
"28
29. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
Share your Hudson plugin with the community
§ Test it and target the lowest API level possible
§ Add Maven metadata
§ Ask hudson-dev@eclipse.org to create a github repo
to host your plugin
§ Create a wiki page on http://wiki.hudson-ci.org
§ Release your plugin with maven to the Sonatype
OSS repo
§ Built on http://ci.hudson-ci.org/
"29
30. EclipseCon NA 2014 — Writing a Hudson / Jenkins plugin
References
§ Hudson Continuous Integration in Practice, by Winston Prakash and Ed Burns
§ Jenkins User Conference 2011 (on slideshare)
§ Hudson (on wikipedia)
§ Writing your first Hudson plugin
§ List of Extension points
§ Writing tests for your plugin
§ Hosting Hudson plugins and Releasing Hudson plugins
§ Hosting and releasing Jenkins Plugins
§ InfoQ : What CI Server do you use ?
§ Developing a plugin for both Jenkins and Hudson
"30