Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name TeamCity Build Queue Enhancer
// @version 1.3.1
// @description Improve the TeamCity build queue by adding filters
// @match http://*teamcity*.com/queue.html
// @grant none
// ==/UserScript==
jq = window.jQuery;
jq(document).ready(function() {
// Change the refresh function so it will reapply the enhancements when the page is refreshed
jq('#buildQueueContainer')[0].refresh = createRefreshFunction('buildQueueContainer', window.location.pathname, '');
enhanceBuildQueue();
});
function enhanceBuildQueue() {
addFilters();
}
function addFilters() {
// Add a filter box
if (getVersion() < 9) {
jq('.buildQueueTableHeader').find('tbody:last').append(
'<tr><td>Filters</td><td></td><td></td><td id="configFilterCel"></td><td></td><td id="triggerFilterCel"></td></tr>');
} else {
jq('.buildQueueTable')
.find('thead:last')
.append(
'<tr><th></th><th></th><th></th><th>Filters</th><th id="configFilterCel"></th><th id="triggerFilterCel"></th><th></th><th></th><th></th><th></th><th></th></tr>');
}
jq('#configFilterCel').append('<input type="search" id="configFilter">');
jq('#triggerFilterCel').append('<input type="search" id="triggerFilter">');
// Filter the queue by hiding unmatched tasks
jq('#configFilter,#triggerFilter').on('input', function() {
filterTasks();
});
// Change the removeAll checkbox so it only checks the filtered tasks
jq('#removeAll').attr('onclick', '');
jq('#removeAll').click(function() {
var checked = jq(this).prop('checked');
jq(getJobElementType() + ':visible').each(function(index) {
jq(this).find('[name=removeItem]').prop('checked', checked);
});
});
}
function getVersion() {
var versionString = jq('span.greyNote').text();
var majorVersion = versionString.substring('Version'.length, versionString.indexOf('.'));
return parseInt(majorVersion);
}
function getJobElementType() {
var jobElementType = 'div.draggable';
if (getVersion() >= 9) {
jobElementType = 'tr.draggable';
}
return jobElementType;
}
function filterTasks() {
var configFilter = jq('#configFilter').val();
var triggerFilter = jq('#triggerFilter').val();
if (configFilter.length === 0 && triggerFilter.length === 0) {
BS.unblockRefresh();
} else {
BS.blockRefreshPermanently();
}
jq(getJobElementType()).each(function(index) {
var configName = jq(this).find('.configurationName').text();
var trigger = jq(this).find('.triggeredBy').text();
var triggerRegEx = new RegExp(triggerFilter, 'i');
if (triggerRegEx.test(trigger)) {
jq(this).show();
} else {
jq(this).hide();
return true; // continue
}
var configRegEx = new RegExp(configFilter, 'i');
if (configRegEx.test(configName)) {
jq(this).show();
} else {
jq(this).hide();
}
});
}
// Copy from existing code with few changes
function createRefreshFunction(b, d, c) {
var a = $(b);
if (!a) {
return Prototype.emptyFunction;
}
return function(i, h, g) {
if (BS.ServerLink && !BS.ServerLink.isConnectionAvailable()) {
BS.Log.info("Connection to server is not available. Refresh is not called.");
return;
}
if (!h) {
h = "";
}
if (i && $(i)) {
BS.Util.show(i);
}
var f = a.refreshUrl;
if (!f) {
f = d;
}
var e = c ? "jsp=" + c : "__fragmentId=" + b + "Inner";
BS.ajaxRequest(f, {
method : "get",
parameters : e + (h ? "&" + h : ""),
onFailure : function() {
BS.Log.warn("Failure while refreshing " + b);
},
onComplete : function(k) {
var j = k.request.getStatus();
var l = !j || (j >= 200 && j < 300);
if (!l) {
return;
}
BS.stopObservingInContainers(a);
BS.Refreshable.destroySortables(a);
a.update(k.responseText);
BS.loadRetinaImages(a);
BS.Util.hide(i);
_.isFunction(g) && g();
enhanceBuildQueue(); // Readd enhancements
}
});
};
}
@WimLeflere
Copy link
Author

WimLeflere commented Mar 10, 2016

TeamCity Build Queue Enhancer

For Google Chrome and Mozilla Firefox
Tested with Chrome Version 38 and later

Description

Script to enhance the TeamCity build queue web interface by adding filter options.
This allows you to filter based on the configuration name and/or the trigger (using regular expressions).

Installation

  • install Tampermonkey on Chrome or Greasemonkey on Firefox
  • install the script
  • change the URL filter if 'http://teamcity.com/queue.html' doesn't match your TeamCity Build Queue URL

Development

The code can be edited in the browser in the Tampermonkey dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment