【发布时间】:2014-11-18 17:19:27
【问题描述】:
我正在使用 dashing.io 做一个小部件,我想根据我在 json 文件中收到的颜色更改 jenkins 作业(我从 Jenkins API 获得)。
ie:工作已完成,我从我的 json 文件中获取颜色值“蓝色”,我希望我的仪表板中的“widget 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
你们能帮帮我吗?我对此真的很陌生,请尝试使其简单。
【问题讨论】:
-
你能发布一些你已经完成的代码吗?
-
给你,谢谢你的关心:)
标签: css json jenkins coffeescript dashing