Tôi đang phát triển một trình cắm thêm Jenkins trong Ruby. Bạn có thể định cấu hình mọi nút kết nối với máy chủ để email được gửi đến địa chỉ được chỉ định khi nút mất kết nối của nó với máy chủ. EmailNodeProperty
thêm một trường để nhập địa chỉ email:Xác nhận các biểu mẫu plugin Jenkins với Ruby
#
# 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
Khi bạn cấu hình một nút, có một trường có tên email
nơi bạn có thể nhập địa chỉ email. Tôi muốn trường này được xác thực khi bạn nhập địa chỉ.
Khi bạn lưu cấu hình, một EmailNodeProperty
được tạo ra từ đó (đúng vậy), bạn có thể truy cập địa chỉ email.
MyComputerListener
's offline
được gọi khi một nút mất kết nối của nó:
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
tìm thấy địa chỉ email và gửi email.
Có ai biết nếu có thể xác thực biểu mẫu trong Ruby không? Theo Jenkins wiki, đây là những gì là nghĩa vụ phải được thực hiện (FIELD là vụ phải được quy đổi thành tên trường, vì vậy tôi đoán nó phải được doCheckEmail
):
public FormValidation doCheckFIELD(@QueryParameter String value) {
if(looksOk(value))
return FormValidation.ok();
else
return FormValidation.error("There's a problem here");
}
Làm thế nào bạn sẽ làm điều này trong Ruby? Phương pháp này nên được triển khai ở đâu? Trong EmailNodeProperty
hoặc trong MyComputerListener
? Làm thế nào để bạn xử lý QueryParameter? Các @ sẽ làm cho nó một biến intstance trong Ruby. (Tham số Truy vấn là gì?)
Bất kỳ trợ giúp nào cũng sẽ được đánh giá cao!
/Jonatan