Quantcast

Can you use build actions in ruby-based plugins?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Can you use build actions in ruby-based plugins?

Rhett Sutphin
Hi,

I'm working on my first Jenkins plugin. I'm using the Jenkins Ruby API. The idea of the plugin is to archive the bundler Gemfile.lock for a ruby project and have Jenkins show you how it changed between builds.

I've got the first part of this working (archiving Gemfile.lock) using a subclass of Jenkins::Tasks::Publisher. It was very easy -- the development environment for ruby plugins (`jpi server`, etc.) is great.

Now I'm trying to add the action which will display the differences. I can't find any examples of using actions from the ruby plugin API, except for an example of a root action in the documentation for Jenkins::Plugin#register_extension. Since the action is build-related, I don't think that register_extension is the right point. As I said, though, I'm completely new to Jenkins plugin development so I may be going at this the wrong way. I've been trying variations on this:

   def perform(build, launcher, listener)
     # ...
     build.native.add_action(Jenkins::Plugin.instance.export(my_action))
   end

If my_action is a subclass of Jenkins::Model::RootAction, the build is not serializable. If my_action just mixes in Jenkins::Model::Action, I get an "unable to find suitable Java Proxy" during the build. I'm using ruby-runtime 0.4, jpi 0.3.3, and jenkins-ruby-runtime 0.1.26.

Are actions supported from the ruby API? If so, can someone give me a pointer on how to construct and add one? (Or if I'm completely misunderstanding what actions are for, a suggestion to go re-read the documentation would be appreciated.)

Thanks,
Rhett


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can you use build actions in ruby-based plugins?

Rhett Sutphin-2
Hi,

On Mar 15, 2012, at 8:29 PM, Rhett Sutphin wrote:

> Hi,
>
> I'm working on my first Jenkins plugin. I'm using the Jenkins Ruby API. The idea of the plugin is to archive the bundler Gemfile.lock for a ruby project and have Jenkins show you how it changed between builds.
>
> I've got the first part of this working (archiving Gemfile.lock) using a subclass of Jenkins::Tasks::Publisher. It was very easy -- the development environment for ruby plugins (`jpi server`, etc.) is great.
>
> Now I'm trying to add the action which will display the differences. I can't find any examples of using actions from the ruby plugin API, except for an example of a root action in the documentation for Jenkins::Plugin#register_extension. Since the action is build-related, I don't think that register_extension is the right point. As I said, though, I'm completely new to Jenkins plugin development so I may be going at this the wrong way. I've been trying variations on this:
>
>   def perform(build, launcher, listener)
>     # ...
>     build.native.add_action(Jenkins::Plugin.instance.export(my_action))
>   end
>
> If my_action is a subclass of Jenkins::Model::RootAction, the build is not serializable. If my_action just mixes in Jenkins::Model::Action, I get an "unable to find suitable Java Proxy" during the build. I'm using ruby-runtime 0.4, jpi 0.3.3, and jenkins-ruby-runtime 0.1.26.
>
> Are actions supported from the ruby API? If so, can someone give me a pointer on how to construct and add one? (Or if I'm completely misunderstanding what actions are for, a suggestion to go re-read the documentation would be appreciated.)

I got past this issue. Here's what I did, in case anyone else has the same problem. First, I upgraded my plugin's dependency to ruby-runtime 0.9 and I upgraded jpi's development Jenkins instance to 1.455. I set up my action like so:

class BundledGems
  include Jenkins::Model::Action

  # ...
end

and I registered a proxy for it by hand:

class BundledGemsProxy
  include Jenkins::Plugin::Proxies::Action
  proxy_for BundledGems
end

Then in my publisher's perform method I did what I had outlined in my previous message:

  def perform(build, launcher, listener)
    # ...
    build.native.add_action(Jenkins.plugin.export(BundledGems.new(...)))
  end

I'm now having a problem rendering the view for the action (org.jruby.exceptions.RaiseException: (NameError) uninitialized constant Rack::VERSION) but I'll post with more details if I can't figure it out.

Thanks,
Rhett
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can you use build actions in ruby-based plugins?

R. Tyler Croy

On Fri, 16 Mar 2012, Rhett Sutphin wrote:

> I got past this issue. Here's what I did, in case anyone else has the same problem. First, I upgraded my plugin's dependency to ruby-runtime 0.9 and I upgraded jpi's development Jenkins instance to 1.455. I set up my action like so:
>
> class BundledGems
>   include Jenkins::Model::Action
>
>   # ...
> end
>
> and I registered a proxy for it by hand:
>
> class BundledGemsProxy
>   include Jenkins::Plugin::Proxies::Action
>   proxy_for BundledGems
> end
>
> Then in my publisher's perform method I did what I had outlined in my previous message:
>
>   def perform(build, launcher, listener)
>     # ...
>     build.native.add_action(Jenkins.plugin.export(BundledGems.new(...)))
>   end
>
> I'm now having a problem rendering the view for the action (org.jruby.exceptions.RaiseException: (NameError) uninitialized constant Rack::VERSION) but I'll post with more details if I can't figure it out.
As somebody also developing with the Ruby plugin support, if you don't mind
updating a few wiki pages, I think it'd be great to start collecting a list of
"how do I do X."

You might also find it useful to join the #jenkins IRC channel and bounce
questions/ideas off of kohsuke, cowboyd, jorgenpt or myself (rtyler).


Cheers
- R. Tyler Croy
--------------------------------------
    Code: http://github.com/rtyler
 Chatter: http://twitter.com/agentdero
          [hidden email]

attachment0 (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can you use build actions in ruby-based plugins?

Rhett Sutphin-2
Hi,

On Mar 17, 2012, at 11:28 PM, R. Tyler Croy wrote:

>
> On Fri, 16 Mar 2012, Rhett Sutphin wrote:
>
>> I got past this issue. Here's what I did, in case anyone else has the same problem. First, I upgraded my plugin's dependency to ruby-runtime 0.9 and I upgraded jpi's development Jenkins instance to 1.455. I set up my action like so:
>>
>> class BundledGems
>>  include Jenkins::Model::Action
>>
>>  # ...
>> end
>>
>> and I registered a proxy for it by hand:
>>
>> class BundledGemsProxy
>>  include Jenkins::Plugin::Proxies::Action
>>  proxy_for BundledGems
>> end
>>
>> Then in my publisher's perform method I did what I had outlined in my previous message:
>>
>>  def perform(build, launcher, listener)
>>    # ...
>>    build.native.add_action(Jenkins.plugin.export(BundledGems.new(...)))
>>  end
>>
>> I'm now having a problem rendering the view for the action (org.jruby.exceptions.RaiseException: (NameError) uninitialized constant Rack::VERSION) but I'll post with more details if I can't figure it out.
>
> As somebody also developing with the Ruby plugin support, if you don't mind
> updating a few wiki pages, I think it'd be great to start collecting a list of
> "how do I do X."

That's a great idea. I'll have to hold off because it turned out the solution above didn't work as well as I thought -- it results in builds serializing in a way that looks correct, but the ruby-based action proxy (BundledGemsProxy) doesn't deserialize as an instance that implements hudson.model.Action and so prevent the job from being loaded when Jenkins restarts. I'm still looking into it, but it will probably be a couple of days before I get back to it.

>
> You might also find it useful to join the #jenkins IRC channel and bounce
> questions/ideas off of kohsuke, cowboyd, jorgenpt or myself (styler).

Thanks for the suggestion. I'll drop by when I get back to working on the plugin.

BTW: just for reference, I've published the in-progress plugin[1].

Rhett

[1]: https://github.com/NUBIC/bundle-recorder-jenkins-plugin

>
>
> Cheers
> - R. Tyler Croy
> --------------------------------------
>    Code: http://github.com/rtyler
> Chatter: http://twitter.com/agentdero
>          [hidden email]

Loading...