Last active
August 29, 2015 14:26
-
-
Save matt-snider/f19a8ef2750cb8aa118c to your computer and use it in GitHub Desktop.
Jenkins Build View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dashing.JenkinsBuildView extends Dashing.Widget | |
ready: -> | |
# This is fired when the widget is done being rendered | |
onData: (data) -> | |
# Handle incoming data | |
# You can access the html node of this widget with `@node` | |
# Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1 class="title" data-bind="title"></h1> | |
<ul class="list"> | |
<li data-foreach-job="jobs"> | |
<p class="title" data-bind="job.title"></p> | |
<div class="job_info"> | |
<span class="name" data-bind="job.name"></span> | |
<span>#<span class="number" data-bind="job.number"></span></span> | |
<span class="duration" data-bind="job.estimatedDuration"></span> | |
<span class="culprits" data-bind="job.culprits"></span> | |
</div> | |
</li> | |
</ul> | |
<p class="updated-at" data-bind="updatedAtMessage"></p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'json' | |
JENKINS_URI = URI.parse('localhost:8080') | |
JENKINS_AUTH = { | |
:username => '', | |
:password => '' | |
} | |
# Defaults to getting information about all jobs | |
JENKINS_JOB_LIST = [] | |
SCHEDULER.every '30s', :first_in => 0 do |job| | |
jobs = get_job_list['jobs'].each { |job| | |
details = get_job_info(job['name']) | |
duration = details['estimatedDuration']/1000 # in seconds | |
m, s = duration/60, duration%60 | |
job['number'] = details['number'] | |
job['estimatedDuration'] = (m > 0 ? '%sm' % m : '') + (s > 0 ? '%ss' % s : '') | |
job['culprits'] = details['culprits'].map{ |info| info['fullName']} | |
} | |
send_event('jenkins-build-view', { title: "Jenkins Build View", jobs: jobs }) | |
end | |
def get_job_list | |
response = request_jenkins_resource('/api/json?tree=jobs[name,color]') | |
jobs = JSON.parse(response.body) | |
if JENKINS_JOB_LIST.any? | |
jobs = jobs.select { |job| JENKINS_JOB_LIST.include? job['name'] } | |
end | |
jobs | |
end | |
def get_job_info(job_name, build = 'lastBuild') | |
job_name = URI.encode(job_name) | |
response = request_jenkins_resource("/job/#{job_name}/#{build}/api/json") | |
JSON.parse(response.body) | |
end | |
def request_jenkins_resource(path) | |
http = Net::HTTP.new(JENKINS_URI.host, JENKINS_URI.port) | |
request = Net::HTTP::Get.new(path) | |
if JENKINS_AUTH['username'] | |
request.basic_auth(JENKINS_AUTH['username'], JENKINS_AUTH['password']) | |
end | |
http.request(request) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Project no longer required and abandoned 😢