我正在用 dashing.io 做一个小部件,我想根据我在 json 文件中收到的颜色更改 jenkins 作业(我从 Jenkins API 获得)。
即:工作已完成,我从我的 json 文件中获取颜色值“蓝色”,并且我希望仪表板上的“小部件 jenkins”上的文本为蓝色。
问题:我真的不知道如何从我的咖啡脚本脚本中的 json 文件中获取我的数据。我也不知道如何更改CSS。
我的 json 文件是这样的:
{
"assignedLabels" : [
{
}
],
"mode" : "NORMAL",
"nodeDescription" : "blabla",
"nodeName" : "",
"numExecutors" : blabla,
"description" : blabla,
"jobs" : [
{
"name" : "JOB_NAME",
"url" : "MY_JOB_URL",
"color" : "blue"
}
]
}
这是我的小部件代码:
require 'net/http'
require 'json'
require 'time'
JENKINS_URI = URI.parse("jenkins_url")
JENKINS_AUTH = {
'name' => 'user',
'password' => 'pwd'
}
def get_json_for_master_jenkins()
http = Net::HTTP.new(JENKINS_URI.host, JENKINS_URI.port)
request = Net::HTTP::Get.new("/jenkins/api/json?pretty=true")
if JENKINS_AUTH['name']
request.basic_auth(JENKINS_AUTH['name'], JENKINS_AUTH['password'])
end
response = http.request(request)
JSON.parse(response.body)
end
# the key of this mapping must be a unique identifier for your job, the according value must be the name that is specified in jenkins
SCHEDULER.every '100s', :first_in => 0 do |job|
thom = get_json_for_master_jenkins()
send_event('master_jobs',
jobs: thom['jobs'][0..4],
colors:thom['jobs']['color']
)
end
你们能帮帮我吗?我对此真的很陌生,请尽量使它简单。