Simple Dashing widget (and associated job) to display teamcity build info. Based on MakePanic/dashing-widgets/teamcity grouped.
This widget displays all children of a teamcity project. Each child project displays the latest build in each branch that is registered in teamcity.
If a build has the state FAILURE
the widgets flashes in red.
If a build has the state INVESTIGATION
the widget shows solid red with an eyeball icon.
The build also displays the name of the user who's check in started the build (or who is investigating the build).
CARVIEW |
Instantly share code, notes, and snippets.
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save jimmirra/76272c91b70ec8ee372b to your computer and use it in GitHub Desktop.
Simple Dashing widget (and associated job) to display teamcity build info. Based on MakePanic/dashing-widgets/teamcity grouped.
This widget displays all children of a teamcity project. Each child project displays the latest build in each branch that is registered in teamcity.
If a build has the state FAILURE
the widgets flashes in red.
If a build has the state INVESTIGATION
the widget shows solid red with an eyeball icon.
The build also displays the name of the user who's check in started the build (or who is investigating the build).
##Dependencies
Add it to dashing's gemfile:
gem 'teamcity-ruby-client'
and run bundle install
. Everything should work now :)
##Usage
- Copy the
team_city.coffee
,team_city.html
andteam_city.scss
files from this gist to thewidgets/team_city
. - Copy
teamcity.rb
tojobs/
- Copy
teamcity.yml
toconfig/
To include the widget in a dashboard, add the following snippet to the dashboard layout file:
<li data-row="1" data-col="1" data-sizex="1" data-sizey="3">
<div data-id="template-data-id1" data-image="/project-icon.png" data-view="TeamCity" data-unordered="carview.php?tsp=true" data-title="TITLE"></div>
</li>
##Settings
Modify the teamcity.yml
config file to work in your teamcity setup. See https://github.com/jperry/teamcity-ruby-client for more information on the teamcity api auth.
The MIT License (MIT)
Copyright (c) 2015 Jim Mirra
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class Dashing.TeamCity extends Dashing.Widget | |
onData: (data) -> | |
# clear existing "status-*" classes | |
$(@get('node')).attr 'class', (i,c) -> | |
c.replace /\bstatus-\S+/g, '' | |
if data.status | |
# add new class | |
$(@get('node')).addClass "status-#{data.status}" |
<h1 class="title" data-bind="title"></h1> | |
<img data-bind-src="image | prepend '/assets'" data-bind-width="width"/> | |
<ul class="list-nostyle"> | |
<li data-foreach-item="items"> | |
<ul> | |
<li class="project" data-foreach-item="item.projects"> | |
<h3 class="project-name" data-bind="item.name"></h3> | |
<ul class="builds" > | |
<li data-foreach-item="item.build_types" | |
data-bind-class="item.last_build.status"> | |
<p> | |
<strong class="build-type-name" data-bind="item.name"></strong> | |
#<span data-bind="item.last_build.number"></span> | |
- <span class="build-type-name" data-bind="item.last_build.username"></span> | |
</p> | |
</li> | |
</ul> | |
</li> | |
</ul> | |
</li> | |
</ul> | |
<p class="more-info" data-bind="moreinfo"></p> | |
<p class="updated-at" data-bind="updatedAtMessage"></p> |
// ---------------------------------------------------------------------------- | |
// Sass declarations | |
// ---------------------------------------------------------------------------- | |
$value-color: #FFF; | |
$background-error-color: #E64040; | |
$background-passed-color: rgba(111, 214, 85, 0.66); | |
$background-investigation-color: #E64040; | |
$background-started-color: #E7D100; | |
$background-no-status-color: rgba(115, 115, 115, 0.73); | |
$title-color: rgba(255, 255, 255, 1); | |
$label-color: rgba(255, 255, 255, 0.7); | |
$moreinfo-color: rgba(255, 255, 255, 0.7); | |
$background: #444; | |
@mixin keyframes($animation-name) { | |
@-webkit-keyframes #{$animation-name} { | |
@content; | |
} | |
@-moz-keyframes #{$animation-name} { | |
@content; | |
} | |
@-ms-keyframes #{$animation-name} { | |
@content; | |
} | |
@-o-keyframes #{$animation-name} { | |
@content; | |
} | |
@keyframes #{$animation-name} { | |
@content; | |
} | |
} | |
@mixin animation($args...) { | |
-webkit-animation: $args; | |
-moz-animation: $args; | |
-ms-animation: $args; | |
-o-animation: $args; | |
animation: $args; | |
} | |
@include keyframes(blink) { | |
0% { opacity: 1.0; } | |
50% { opacity: 0.0; } | |
100% { opacity: 1.0; } | |
} | |
// ---------------------------------------------------------------------------- | |
// Widget-list styles | |
// ---------------------------------------------------------------------------- | |
.widget-team-city{ | |
background-color: $background; | |
vertical-align: top !important; | |
h1{ | |
text-transform: none; | |
} | |
h3{ | |
font-size: 15px; | |
margin: 5px 0; | |
font-weight: lighter; | |
} | |
img { | |
position: absolute; | |
top: 30px; | |
left: 50px; | |
margin: 0 auto; | |
opacity: 0.05; | |
max-width: 80%; | |
max-height: 80%; | |
} | |
.title, strong{ | |
color: $title-color; | |
} | |
ul { | |
margin: 0; | |
text-align: left; | |
list-style: none; | |
color: $label-color; | |
} | |
li { | |
margin-bottom: 3px; | |
} | |
.project{ | |
.project-name{ | |
padding-top: 5px; | |
} | |
} | |
.builds{ | |
p{ | |
padding: 8px; | |
} | |
li{ | |
background-color: $background-no-status-color; | |
} | |
margin-bottom: 5px; | |
.SUCCESS{ | |
background-color: $background-passed-color; | |
} | |
.FAILURE{ | |
background-color: $background-error-color; | |
@include animation(blink 1s step-start 0s infinite); | |
} | |
.INVESTIGATION{ | |
span:before{ | |
content: "\f06e"; | |
font-family: FontAwesome; | |
padding-right: 3px; | |
} | |
background-color: $background-investigation-color; | |
} | |
.build-type-name{ | |
font-size: 17px; | |
} | |
} | |
.updated-at { | |
color: rgba(0, 0, 0, 0.3); | |
} | |
.more-info { | |
color: $moreinfo-color; | |
} | |
} |
require 'teamcity' | |
def update_builds(project_id) | |
builds = [] | |
projects = [] | |
TeamCity.project(:id => project_id).projects.project.each do |project| | |
build_types = [] | |
TeamCity.project_buildtypes(:id => project.id).each do |build_type| | |
build_types.push({ | |
:id => build_type.id, | |
:name => build_type.name | |
}) | |
end | |
build_types.each do |build_type_obj| | |
build_type_obj_builds = TeamCity.builds(:count => 1, :buildType => build_type_obj[:id]) | |
unless build_type_obj_builds.nil? | |
last_build = build_type_obj_builds.first | |
uname = TeamCity.build(:id => last_build.id).lastChanges.change.first["username"] | |
# see if current build is under investigation | |
bt = TeamCity.buildtype(id: build_type['id']) | |
if bt.investigations | |
last_build.status = 'INVESTIGATION' | |
begin | |
investigation_assignee = TeamCity.buildtype_investigations(build_type['id']).first['assignee'].username | |
uname = investigation_assignee | |
rescue | |
uname = 'Unassigned' | |
end | |
end | |
build_type_obj['last_build'] = { | |
:id => last_build.id, | |
:number => last_build.number, | |
:state => last_build.state, | |
:status => last_build.status, | |
:username => uname | |
} | |
end | |
end | |
projects.push({ | |
:name => project.name, | |
:id => project.id, | |
:description => project.description, | |
:build_types => build_types | |
}) | |
end | |
build_info = { | |
:title => project_id, | |
:projects => projects | |
} | |
builds << build_info | |
builds | |
end | |
config_file = File.dirname(File.expand_path(__FILE__)) + '/../config/teamcity.yml' | |
config = YAML::load(File.open(config_file)) | |
TeamCity.configure do |c| | |
c.endpoint = config['api_url'] | |
c.http_user = config['http_user'] | |
c.http_password = config['http_password'] | |
end | |
SCHEDULER.every '33s', :first_in => '1s' do | |
if config['repositories'].nil? | |
puts 'No TeamCity repositories found :(' | |
else | |
config['repositories'].each do |data_id, build_id| | |
send_event(data_id, { :items => update_builds(build_id)}) | |
end | |
end | |
end |
api_url: "https://my-teamcity-installation.tld/httpAuth/app/rest/" | |
http_user: "my-http-user" | |
http_password: "my-http-password" | |
repositories: | |
template-data-id1: project1Id | |
template-data-id2: project2Id |
Any chance you could take a look at modifying this script to work with TC9? I'm happy to help/be a test subject if needed.