Checking Jenkins Plugins with Ruby

I am developing a Jenkins plugin in Ruby. It is assumed that you can configure each node that connects to the server so that an email address is sent to the specified address when the node loses its connection with the master. EmailNodeProperty adds a field for entering an email address:

 # # Save an email property for every node # class EmailNodeProperty < Jenkins::Slaves::NodeProperty require 'java' import 'hudson.util.FormValidation' display_name "Email notification" attr_accessor :email def initialize(attrs = {}) @email = attrs['email'] end def doCheckEmail value puts " ENP.doCheckEmail:#{value}" end end 

When configuring node, a field appears with the name email , where you can enter an email address. I want this field to be checked when entering the address.

When you save the configuration, an EmailNodeProperty is created, from where (on the right) you can access the email address.

MyComputerListener offline is called when node loses its connection:

 class MyComputerListener include Jenkins::Slaves::ComputerListener include Jenkins::Plugin::Proxy def online(computer, listener) end def offline(computer) #Do nothing when the Master shuts down if computer.to_s.match('Master') == nil list = computer.native.getNode().getNodeProperties() proxy = list.find {"EmailNodeProperty"} if proxy.is_a?(Jenkins::Plugin::Proxy) rubyObject = proxy.getTarget() email = rubyObject.email #<= Accesses the email from EmailNodeProperty [...] end end end end 

MyComputerListener finds an email address and sends an email.

Does anyone know if form validation is possible in Ruby? According to the Jenkins wiki , this is what should be implemented (FIELD is supposed to be exchanged for the field name, so I think it should be doCheckEmail ):

 public FormValidation doCheckFIELD(@QueryParameter String value) { if(looksOk(value)) return FormValidation.ok(); else return FormValidation.error("There a problem here"); } 

How do you do this in Ruby? Where should the method be implemented? In EmailNodeProperty or in MyComputerListener ? How do you handle QueryParameter? A value of @ would make this an intstance variable in Ruby. (What is a Queryparameter?)

Any help would be greatly appreciated!

/ Jonathan

+8
ruby validation jruby jenkins jenkins-plugins
source share
1 answer

It simply does not exist today, and we really need to add it. It was picked up several times on Thursday morning to crack the session , so it is high on the TODO list. But with the ruby-runtime-plugin 0.10 , this is simply not possible. Sorry to let you down.

+1
source share

All Articles