Skip to content

Instantly share code, notes, and snippets.

@gsomoza
Created February 15, 2024 14:27
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 gsomoza/81c0067b7e89b1898060b176b58e9dcf to your computer and use it in GitHub Desktop.
Save gsomoza/81c0067b7e89b1898060b176b58e9dcf to your computer and use it in GitHub Desktop.
Jenkins Job Total Durations
/*
* Run this on the Blue Ocean activity page to add up all job durations visible on that page.
*/
(function(){
const durations = [...document.querySelectorAll('[data-runid] a:nth-of-type(5) span')].map(i => i.textContent);
console.log(durations);
const validDurations = durations.filter(duration => !duration.startsWith("<"));
const totalSeconds = validDurations.reduce((total, current) => {
const parts = current.split(" ");
let hours = 0;
let minutes = 0;
let seconds = 0;
parts.forEach(part => {
if (part.includes('h')) {
hours += parseInt(part);
} else if (part.includes('m')) {
minutes += parseInt(part);
} else if (part.includes('s')) {
seconds += parseInt(part);
}
});
// Convert hours to minutes and add them to the total minutes, then add seconds
return total + (hours * 60) + minutes + (seconds / 60);
}, 0);
const formatTotalDuration = (totalMinutes) => {
const minutes = Math.floor(totalMinutes);
const seconds = Math.round((totalMinutes - minutes) * 60);
return `${minutes}m${seconds > 0 ? " " + seconds + "s" : ""}`;
};
const averageMinutes = totalSeconds / validDurations.length;
console.log(`Total Duration: ${formatTotalDuration(totalSeconds)}`);
console.log(`Average Duration: ${formatTotalDuration(averageMinutes)}`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment