Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F27206579
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e7adf7a..2f63746 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,61 +1,73 @@
# Changelog
All notable changes to this project will be documented in this file.
This project adheres to [semantic versioning](https://semver.org/).
+## [1.0.1] - 2018-09-21
+### Deprecated
+- HUDSON_URL environment variable is now deprecated.
+ Use JENKINS_URL instead. Will be removed in 2.0.
+
+### Changed
+- You can still use the deprecate HUDSON_URL environment
+ variable. The server will print a deprecation notice.
+
+### Fixed
+- Fix issue where builds URL were not show anymore.
+
## [1.0.0] - 2018-09-21
### Added
- Jenkins 2.0 multi-branch pipelines are supported.
### Changed
- JENKINS_URL must be used instead of HUDSON_URL to configure instance.
- An exit code 1 is provided when the configuration is missing.
- Recommended Docker image is now nasqueron/tommy.
- Documentation is improved.
### Fixed
- Dependencies and suggested Ruby version upgrade
- Code style has been improve to adhere to another
bunch of Ruby community conventions.
## [0.7.0] - 2016-08-01
### Added
- Favicon and associated mobile/browsers artifacts are provided.
## [0.6.0] - 2016-07-25
### Changed
- CSS units are simplified.
- Documentation is improved.
## [0.5.0] - 2016-07-21
### Added
- /status route to ease infrastructure test.
## [0.4.0] - 2016-07-11
### Changed
- Code has been refactored to ease maintainability
and adhere to most Ruby community conventions.
- Dependencies: crack is no longer used, as we parse
JSON natively.
### Fixed
- Ensure compatibility with new Jenkins jobs not yet built.
## [0.3.0] - 2016-01-07
### Fixed
- Template projects (so non buildable) won't break
the dashboard anymore.
- Dependencies: active_support → activesupport.
## [0.2.0] - 2012-03-15
### Fixed
- Various fixes by Brian Carstensen.
## [0.1.0] - 2012-03-08
### Changed
- New design.
- Dependencies: removed Shotgun in production.
- Various fixes by Brian Carstensen.
## [0.0.1] - 2011-09-14
### Added
- Initial version by Arfon Smith.
diff --git a/tommy.rb b/tommy.rb
index 22884be..554dfd4 100644
--- a/tommy.rb
+++ b/tommy.rb
@@ -1,217 +1,246 @@
# frozen_string_literal: true
# -------------------------------------------------------------
# Tommy - Visualisation dashboard for Jenkins
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Author: Arfon Smitn (Zooniverse)
# Maintainer: Sebastien Santoro aka Dereckson
# Project: Nasqueron
# Created: 2011-09-14
# Dependencies: Sinatra
# -------------------------------------------------------------
require 'rest-client'
require 'active_support/all'
require 'hashie'
require 'erb'
require 'sinatra'
# -------------------------------------------------------------
# Table of contents
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
# :: Environment
# :: Project class
# :: Controller
# :: Routes
# :: Helpers
#
# -------------------------------------------------------------
# -------------------------------------------------------------
# Environment
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
begin
JENKINS_URL = ENV.fetch('JENKINS_URL')
rescue KeyError
- $stderr.write %(You must define JENKINS_URL to your Jenkins instance URL.
+ # HUDSON_URL is deprecated and will be removed in Tommy 2.0.
+ if ENV.include? 'HUDSON_URL'
+ JENKINS_URL = ENV['HUDSON_URL']
+ $stderr.write %(\e[31m
+╔══════════════════════════════════════════════════════════╗
+║ *** DEPRECATION NOTICE *** ║
+╟──────────────────────────────────────────────────────────╢
+║ ║
+║ You currently use the HUDSON_URL environment variable ║
+║ to configure your Jenkins (or Hudson?) instance URL. ║
+║ ║
+║ As Hudson isn't maintained anymore, we're migrating this ║
+║ setting to JENKINS_URL. ║
+║ ║
+║ Simply replace HUDSON_URL by JENKINS_URL in your Docker ║
+║ or service configuration. ║
+║ ║
+║ The current setting is deprecated and will be dropped ║
+║ in a future version (plan is Tommy 2.0). ║
+║ ║
+║ Reference: https://devcentral.nasqueron.org/T1448 ║
+║ ║
+╚══════════════════════════════════════════════════════════╝
+\e[0m
+)
+ else
+ $stderr.write %(You must define the JENKINS_URL environment variable
+to point to your Jenkins instance URL, without trailing slash.
-If you need to pass credentials, you can use the syntax https://username:password@jenkins.domain.tld.
+If you need to pass credentials, you can use the following syntax:
+https://username:password@jenkins.domain.tld
)
- exit 1
-end
+ exit 1
+ end
+end
# -------------------------------------------------------------
# Project class
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##
# This class represents a defined or discrete hash for a Jenkins project.
class Project < Hashie::Dash
property :name
property :build_score
property :last_build_number
property :last_build_url
property :last_stable_build
property :health_report
property :last_complete_url
property :last_failed_url
property :colour
##
# Builds a project name from a name and a prefix
# Returns a string.
def self.build_name(name, prefix)
return name if prefix.nil?
[prefix, name.tr('-', ' ')].join(' / ')
end
##
# Parses a job element of the Jenkins API.
# Returns a Project instance.
def self.parse_project(data, prefix = nil)
name = build_name(data['displayName'], prefix)
project = Project.new(
name: name,
last_build_number: data['builds'].first['number'],
colour: data['color']
)
if data['healthReport']
project.build_score = data['healthReport'].first['score'].to_i
project.health_report = data['healthReport'].first['description']
end
unless data['lastStableBuild'].blank?
project.last_stable_build = data['lastStableBuild']['number']
end
urls = {
'lastBuild' => 'last_build_url=',
'lastCompletedBuild' => 'last_complete_url=',
'lastFailedBuild' => 'last_failed_url='
}
urls.each do |api_property, local_property|
next if data[api_property].blank?
project.send(local_property, data[api_property]['url'])
end
project
rescue NoMethodError
nil
end
def self.multi_project?(data)
data['_class'].start_with?('org.jenkinsci.plugins.workflow.multibranch')
end
##
# Parses a JSON API reply into an array of Project instances
def self.parse_incoming_json(json)
projects = []
json['jobs'].each do |job|
parse_projects(job).each do |project|
projects << project unless project.nil?
end
end
projects
end
def self.parse_projects(job)
if multi_project?(job)
parse_multi_projects(job)
else
[parse_project(job)]
end
end
def self.parse_multi_projects(root_job)
projects = []
prefix = root_job['name']
root_job['jobs'].each do |job|
projects << parse_project(job, prefix)
end
projects
end
##
# Determines if a build is green
def green?
last_stable_build == last_build_number
end
##
# Determines if a build is still building
def building?
colour.include?('anime')
end
end
# -------------------------------------------------------------
# Controller
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def prepare_dashboard
json = RestClient::Resource.new("#{JENKINS_URL}/api/json?depth=2")
@projects = Project.parse_incoming_json(JSON.parse(json.get))
erb :index
end
# -------------------------------------------------------------
# Routes
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
get '/' do
prepare_dashboard
end
get '/manifest.json' do
content_type 'application/json'
erb :manifest
end
get '/status' do
'ALIVE'
end
# -------------------------------------------------------------
# Helpers
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
helpers do
def css_scores
{
100 => 'best',
80 => 'better',
60 => 'good',
40 => 'bad',
0 => 'worse'
}
end
def css_for_score(score)
css_scores.each do |threshold, css_class|
return css_class if score >= threshold
end
raise 'Specify in scores a value for the lower score you can get.'
end
def css_for_project(project)
if project.green?
css_for_score(project.build_score)
elsif project.building?
'building'
else
'worst'
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, May 3, 04:33 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3677620
Default Alt Text
(9 KB)
Attached To
Mode
rTOMMY Tommy
Attached
Detach File
Event Timeline
Log In to Comment