Skip to content

Instantly share code, notes, and snippets.

@maxmarkus
Created February 23, 2017 06:31
Show Gist options
  • Save maxmarkus/d6e92d6df985ee4eecbb1f8eeff4d82d to your computer and use it in GitHub Desktop.
Save maxmarkus/d6e92d6df985ee4eecbb1f8eeff4d82d to your computer and use it in GitHub Desktop.
Adds a link to Queue and Jobs for killing all of them. Be aware - as soon as you click the links, all currently shown jobs or queues will be cancelled without asking.
// ==UserScript==
// @name Jenkins kill BuildQueue + Jobs
// @namespace http://jenkins
// @version 0.1
// @description try to take over the world!
// @author Markus
// @match https://jenkins.prod.sevenup.ycd.ydev.hybris.com:10000/*
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==
(function() {
var jenkinsPath = 'https://jenkins.prod.sevenup.ycd.ydev.hybris.com:10000';
var makeid = function() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
};
var settings = {
"async": true,
"crossDomain": true,
"url": null,
"method": "POST",
"headers": {
"accept": "text/javascript, text/html, application/xml, text/xml, */*",
"x-prototype-version": "1.7",
"x-requested-with": "XMLHttpRequest",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"cache-control": "no-cache"
}
};
var killQueue = function(baseLink, selector){
console.log('tampermonkey - killing ' + jQuery(selector).length + ' jobs');
jQuery(selector).each(function(elem, index){
var targetHref = jQuery(this).attr('href');
console.log('cancelling', targetHref);
settings.url = baseLink + targetHref;
$.ajax(settings).done(function(response) { console.log('done'); });
});
};
var addKillLink = function(selector, prependSelector, linkText, baseLink) {
var newSelect = makeid();
jQuery(prependSelector).prepend('<a class="collapse ' + newSelect + '" style="cursor:pointer">' + linkText + '</a>');
jQuery('.' + newSelect).on('click', function() { killQueue(baseLink, selector); });
};
addKillLink('#buildQueue .stop-button-link', '#buildQueue .pane-header', 'Kill Queue!', jenkinsPath);
addKillLink('#executors .stop-button-link', '#executors .pane-header', 'Kill Jobs!', jenkinsPath);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment