Enable Project properties & build actions programatically

20 views
Skip to first unread message

HarteJoe

unread,
Mar 19, 2016, 1:23:24 PM3/19/16
to Jenkins Developers
Hi folks,

I am a first time Jenkins developer with the intention of writing a new plugin. I have many builds (pipelines) that follow a very common format, and it has become cumbersome to perform the same configuration on them all.
I'd like to write a plugin that can automatically add certain properties and post build steps to jobs of a certain kind. For example, ensure that JUnit, FindBugs and PMD are always enabled for these jobs.
I'm not certain where to get started on how I can programatically add build actions to a job once I have a reference to the job item.

Any pointers in the right direction would be very much appreciated.

Thank you

Robert Sandell

unread,
Mar 21, 2016, 6:34:44 AM3/21/16
to jenkin...@googlegroups.com
Are you talking about adding information Actions to the build records or configuring actual build steps to run?

Both are quite easy to do but different. There are a couple of plugins that does the latter already, the first ones that comes to mind is Configuration Slicing [1] and Job DSL plugin [2].

Configuring a build step programmaticly would be something like

if (job.getPublishersList().get(FindBugsPublisher.class) == null) {
FindBugsPublisher findBugs = new FindBugsPublisher();
findBugs.setPattern("**/findbugs.xml");
job.getPublishersList().add(findBugs);
}
But not all plugins keep their api stable for external calls like this so it might break if you upgrade findbugs beyond 4.63 for example, so you might be safer in doing something like job dsl is doing and generate the xml for the publisher config you're after, inserting it into the job's config.xml and do a
job.doReload();

Although bugs are known to have manifested in some plugins that don't handle reload from disk very well, at least I am known to not have handled it well in mine ;) But the Job DSL plugin is a quite popular plugin (it also does a reload iirc) so let's hope most of those bugs have been found by now.

[1] https://wiki.jenkins-ci.org/display/JENKINS/Configuration+Slicing+Plugin
[2] https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin

/B


--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/10aea3fb-555f-4b0f-8b97-cec01724d2bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees Inc.
Reply all
Reply to author
Forward
0 new messages