Я попытался настроить виджет состояния сборки, основанный на фреймворке Dashing / Smashing.Код для того же, что и ниже, и когда я запускаю процесс лишения / разбивания, я получаю сообщение об ошибке.Похоже, что виджет не может получить доступ к URL, тогда как вручную я могу получить доступ к URL (http://127.0.0.1:8008/jenkins/job/DEMO/api/json), а также похоже, что сообщение об ошибке приходит из вызова Jenkins API.
require 'net/http'
require 'json'
require 'time'
JENKINS_URI = URI.parse("http://127.0.0.1:8008/jenkins/")
JENKINS_AUTH = {
'name' => 'admin',
'password' => 'admin123'
}
# 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
job_mapping = {
'job1' => { :job => 'DEMO'},
}
def get_number_of_failing_tests(job_name)
info = get_json_for_job(job_name, 'lastCompletedBuild')
info['actions'][4]['failCount']
end
def get_completion_percentage(job_name)
build_info = get_json_for_job(job_name)
prev_build_info = get_json_for_job(job_name, 'lastCompletedBuild')
return 0 if not build_info["building"]
last_duration = (prev_build_info["duration"] / 1000).round(2)
current_duration = (Time.now.to_f - build_info["timestamp"] / 1000).round(2)
return 99 if current_duration >= last_duration
((current_duration * 100) / last_duration).round(0)
end
def get_json_for_job(job_name, build = 'lastBuild')
job_name = URI.encode(job_name)
http = Net::HTTP.new(JENKINS_URI.host, JENKINS_URI.port)
request = Net::HTTP::Get.new("/job/#{job_name}/#{build}/api/json")
if JENKINS_AUTH['name']
request.basic_auth(JENKINS_AUTH['name'], JENKINS_AUTH['password'])
end
response = http.request(request)
JSON.parse(response.body)
end
job_mapping.each do |title, jenkins_project|
current_status = nil
SCHEDULER.every '10s', :first_in => 0 do |job|
last_status = current_status
build_info = get_json_for_job(jenkins_project[:job])
current_status = build_info["result"]
if build_info["building"]
current_status = "BUILDING"
percent = get_completion_percentage(jenkins_project[:job])
elsif jenkins_project[:pre_job]
pre_build_info = get_json_for_job(jenkins_project[:pre_job])
current_status = "PREBUILD" if pre_build_info["building"]
percent = get_completion_percentage(jenkins_project[:pre_job])
end
send_event(title, {
currentResult: current_status,
lastResult: last_status,
timestamp: build_info["timestamp"],
value: percent
})
end
end
Сообщение об ошибке:
<code>$ smashing start
Thin web server (v1.7.2 codename Bachmanity)
Maximum connections set to 1024
Listening on 0.0.0.0:3030, CTRL+C to stop
{ 47249764683760 rufus-scheduler intercepted an error:
47249764683760 job:
47249764683760 Rufus::Scheduler::EveryJob "10s" {:first_in=>0}
47249764683760 error:
47249764683760 47249764683760
47249764683760 JSON::ParserError
47249764683760 784: unexpected token at '<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /job/DEMO/lastBuild/api/json. Reason:
<pre> Not Found
Powered by Jetty: // 9.4.z-SNAPSHOT '47249764683760 /home/smashing/.rbenv/versions/2.3.7/lib/ruby/2.3.0/json/common.rb:156:in `parse' 47249764683760 /home/smashing/.rbenv/versions/2.3.7/lib/ruby/2.3.0/json/common.rb:156:in `parse '47249764683760 /home/smashing/my-project/jobs/jenkins_build.rb:41:in` get_json_for_job' 47249764683760/home/smashing/my-project/jobs/jenkins_build.rb:48:in` блок (2 уровня) в'47249764683760 /home/smashing/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.4.2/lib/rufus/scheduler/jobs.rb:210:in `do_call '47249764683760 /home/smashing/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.4.2/lib/rufus/scheduler/jobs.rb:254:in`trigger_now '47249764683760 /home/smashing/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.4.2/lib/rufus/scheduler/jobs.rb:296:в `block (3 уровня) в start_work_thread '47249764683760 /home/smashing/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.4.2/lib/rufus/scheduler/jobs.rb:299:in `блок (2 уровня) в start_work_thread '47249764683760 /home/smashing/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.4.2 / lib / rufus / scheduler / jobs.rb: 285: в "цикле" 47249764683760 /home/smashing/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/rufus-scheduler-3.4.2 / lib / rufus / scheduler / jobs.rb: 285: в `block in start_work_thread '47249764683760 tz: 47249764683760 ENV [' TZ ']: 47249764683760 Time.now: 2019-07-05 17:03:56 +0530 47249764683760 local_tzone: #47249764683760 et-orbi: 47249764683760 (etz: nil, tnz: "IST", tziv: "2.0.0", tzidv: nil, rv: "2.3.7", rp: "x86_64-linux", win: false, rorv: ноль, astz: ноль, eov "1.2.1", eotnz: #, eotnfz: "+ 0530", eotlzn: "Азия / Калькутта", eotnfZ: "IST", debian: ноль, centos: ноль, osx: "Азия / Калькутта")} 47249764683760 частота: 0,3 47249764683760 scheduler_lock: #47249764683760 trigger_lock: #47249764683760 время работы: 0,30658841133117676 (306) 47249764683760 вниз?: False 47249764683760 потоков: 2 47249764683760 поток: #47249764683760 thread_key: rufus_scheduler_47249768596520 47249764683760 work_threads: 1 47249764683760 активен: 1 47249764683760 вакантными: 0 47249764683760 max_work_threads: 28 47249764683760 мьютексы: {} 47249764683760 вакансии: 4 47249764683760 at_jobs: 0 47249764683760 in_jobs: 0 47249764683760 every_jobs: 4 47249764683760 interval_jobs: 0 47249764683760 cron_jobs: 0 47249764683760running_jobs: 1 47249764683760 work_queue: 0} 47249764683760.
Любая помощь / указатели будут оценены.