Jenkins Trigger in Ruby

12 views
Skip to first unread message

Harry Wilkinson

unread,
Oct 23, 2011, 3:12:16 PM10/23/11
to jenkin...@googlegroups.com, cow...@thefrontside.net
Hello,

I've read some of the recent Jenkins mailing list activity about Ruby-based plugins with great interest.  There's a particular kind of build trigger (for GitHub pull requests) that I'd love to have, and it seems like the best way to get it is to create it myself, but I have no experience with Java; I've used Ruby quite a bit, though, so the work that's been done with the Ruby plugin looks really promising.

So, my question: is it possible/practical to create triggers in Ruby with what's done so far?  I don't know too much (only what I've read) about Jenkins development, but it looks like triggers might be a little different to the build steps that (as far as I can tell) are supported in Ruby so far.  Would it be a matter of creating a new model and task (and maybe a new proxy?) in the jenkins-plugin-runtime gem?  

Sorry if this is naive; I'm trying to figure out how this all fits together.

Thanks.

Harry

Charles Lowell

unread,
Oct 23, 2011, 3:56:53 PM10/23/11
to Harry Wilkinson, jenkin...@googlegroups.com, jenk...@googlegroups.com
On Oct 23, 2011, at 2:12 PM, Harry Wilkinson wrote:

Hello,

I've read some of the recent Jenkins mailing list activity about Ruby-based plugins with great interest.  There's a particular kind of build trigger (for GitHub pull requests) that I'd love to have, and it seems like the best way to get it is to create it myself, but I have no experience with Java; I've used Ruby quite a bit, though, so the work that's been done with the Ruby plugin looks really promising.

The short answer is that it is definitely possible to create triggers in Ruby. The long answer is that we have yet to wrap the trigger interface into "native" Ruby, so you will need to implement the Java interface in Ruby, and then optionally implement a proxy to make it nice.



So, my question: is it possible/practical to create triggers in Ruby with what's done so far?  I don't know too much (only what I've read) about Jenkins development, but it looks like triggers might be a little different to the build steps that (as far as I can tell) are supported in Ruby so far.  Would it be a matter of creating a new model and task (and maybe a new proxy?) in the jenkins-plugin-runtime gem?

Yes, you will need to implement the Java interface with Ruby first. Then, once you have that working, you can convert your Java class (which is implemented in Ruby) into a proxy that wraps a plain old Ruby object. This is generally what I do. Does that make sense?

So, after you create your plugin with the 'jpi' tool. make  a file called "my_trigger.rb" in the models/ directory. It might look something like this:

<Ruby>

class MyTrigger < Java.hudson.triggers.Trigger 
def start(job)
           #code to do stuff here
        end
end

#now we need to explicitly register this, since it's not yet an "official" proxy interface, and it won't happen automatically
Jenkins::Plugin.instance.register_describable MyTrigger, Java.hudson.triggers.Trigger

</Ruby>

And you should be good to go. Keep in mind that this class is implementing a Java interface, and as such it receives Java objects in its methods, and must return Java objects that conform to the interface.

Can somebody from the Java part of the Jenkins community tell me if this will actually work? I noticed that the hudson.triggers.Trigger class is parameterized by Item... Does this class factor into when the trigger is invoked?


Sorry if this is naive; I'm trying to figure out how this all fits together.

It's daunting at first, especially since we have about 1% of all extension points available, but hopefully this will get you in the right direction.


Thanks.

Harry

cheers,
Charles


Harry Wilkinson

unread,
Oct 23, 2011, 6:35:50 PM10/23/11
to Charles Lowell, jenkin...@googlegroups.com, jenk...@googlegroups.com
Thanks for the advice Charles.  I will have a play with it and see what happens.

Much appreciated.

Harry
Reply all
Reply to author
Forward
0 new messages