Skip to content

Instantly share code, notes, and snippets.

@dcutting
Forked from gavinbunney/README.md
Last active December 24, 2015 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcutting/404cda2c68c191f0488b to your computer and use it in GitHub Desktop.
Save dcutting/404cda2c68c191f0488b to your computer and use it in GitHub Desktop.

Bamboo Plan Dashing Widget

Dashing widget to display plan build details from your Bamboo instance.

Forked from Gavin Bunney.

Installation

Automatic

To install this widget, run this command from your Dashing directory:

dashing install 404cda2c68c191f0488b

Manual

  1. Copy the below coffee/scss/html files into a widget folder named bamboo_build
  2. Copy the bamboo_build.rb file into the jobs folder
  3. Copy the bamboo-logo.png file into the assets\images folder

Usage

Update job

Update the configuration element in the bamboo_build.rb file with your bamboo instance uri and the plans you wish to monitor.

configuration = {
    :bamboo_uri => 'http://bamboo:8085',
    :rest_endpoint => '/rest/api/latest',
    :credentials => {
         :username => '',
         :password => ''
     },
    :refresh_rate => '10s',
    :plan_keys => %w[PLAN-ONE PLAN-TWO PLAN-THREE]
}

Add to dashboard

To include this widget in your dashboard, add the following snippet of code to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="PLAN-ONE" data-view="BambooBuild" data-title="Plan 1 Build"></div>
</li>

You'll need to update the data-id with the name of your plan to show as defined in the bamboo_build.rb file.

class Dashing.BambooBuild extends Dashing.Widget
@accessor 'value', Dashing.AnimatedValue
constructor: ->
super
refreshWidgetState: =>
node = $(@node)
node.removeClass('successful failed unknown')
node.addClass(@get('state').toLowerCase())
ready: ->
@refreshWidgetState()
onData: (data) ->
@refreshWidgetState()
<h1 class="title" data-bind="title"></h1>
<h2 class="large-font" data-bind="number"></h2>
<h2 class="state" data-bind="state"></h2>
<p class="duration" data-bind="duration"></p>
<p class="finished" data-bind="finished"></p>
require 'net/https'
require 'json'
#--------------------------------------------------------------------------------
# Configuration
#--------------------------------------------------------------------------------
configuration = {
:bamboo_uri => 'http://bamboo:8085',
:rest_endpoint => '/rest/api/latest',
:credentials => {
:username => '',
:password => ''
},
:refresh_rate => '10s',
:plan_keys => %w[PLAN-ONE PLAN-TWO PLAN-THREE]
}
#--------------------------------------------------------------------------------
class BambooBuild
def initialize(base_uri, rest_endpoint, credentials)
@base_uri = base_uri
@rest_endpoint = rest_endpoint
@credentials = credentials
end
def plan_status(plan_key)
begin
uri = URI.parse(@base_uri)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
request = Net::HTTP::Get.new(result_endpoint(plan_key))
if @credentials && @credentials[:username].length > 0
request.basic_auth @credentials[:username], @credentials[:password]
end
response = http.request(request)
response_json = JSON.parse(response.body)
latest_build = response_json['results']['result'][0]
return {
:state => latest_build['state'],
:number => latest_build['number'],
:duration => latest_build['buildDurationDescription'],
:finished => latest_build['buildRelativeTime']
}
rescue => e
puts "Error getting bamboo plan status: #{e}"
return {
:state => 'Unknown',
:number => '?',
:duration => '',
:finished => ''
}
end
end
private
def result_endpoint(plan_key)
auth_param = ''
if @credentials && @credentials[:username].length > 0
auth_param = 'os_authType=basic&'
end
"#{@rest_endpoint}/result/#{plan_key}.json?#{auth_param}expand=results.result&max-results=1"
end
end
def get_plan_status(bamboo_uri, rest_endpoint, credentials, job)
build = BambooBuild.new(bamboo_uri, rest_endpoint, credentials)
build.plan_status(job)
end
configuration[:plan_keys].each do |plan_key|
SCHEDULER.every configuration[:refresh_rate], :first_in => 0 do |_|
status = get_plan_status(configuration[:bamboo_uri], configuration[:rest_endpoint], configuration[:credentials], plan_key)
send_event(plan_key, status)
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$state-color: #fff;
$background-color: #4b4b4b;
$background-failed-color: #d26771;
$background-successful-color: #96bf48;
$background-unknown-color: #999;
$title-color: rgba(255, 255, 255, 1);
$label-color: rgba(255, 255, 255, 0.7);
$duration-color: rgba(255, 255, 255, 0.7);
$finished-color: rgba(0, 0, 0, 0.3);
.widget-bamboo-build {
vertical-align: top;
.title {
color: $title-color;
}
.state {
text-align: center;
display: block;
font-weight: 600;
color: $state-color;
font-size: 40px;
word-wrap: break-word;
}
.finished {
color: $finished-color;
position: absolute;
bottom: 24px;
left: 0;
right: 0;
}
.duration {
color: $duration-color;
position: absolute;
bottom: 48px;
left: 0;
right: 0;
}
&.failed {
background-color: $background-failed-color;
}
&.unknown {
background-color: $background-unknown-color;
}
&.successful {
background-color: $background-successful-color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment