Jenkins - Redirect Native UI to Blue Ocean

Redirect the native Jenkins UI to Blue Ocean

安装此脚本?
作者推荐脚本

您可能也喜欢Jenkins - Compare Before Promoting

安装此脚本
  1. // ==UserScript==
  2. // @name Jenkins - Redirect Native UI to Blue Ocean
  3. // @namespace https://greasyfork.org/en/scripts?by=1388261
  4. // @version 1.1
  5. // @description Redirect the native Jenkins UI to Blue Ocean
  6. // @author nate.clark@hear.com
  7. // @match https://jenkins.audibene.net/job/*/job/*/job/*/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=audibene.net
  9. // @tag productivity
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const shouldConfirm = (window.localStorage.getItem('AUTO_REDIRECT') ?? 'false').toLowerCase() === 'false'
  17. const url = window.location.href
  18. const parameterizedUrl = "https://jenkins.audibene.net/blue/organizations/jenkins/:organizationId%2F:repo/detail/:pr/:run/pipeline/";
  19.  
  20. const regex = /https:\/\/jenkins\.audibene\.net\/job\/(?<organizationId>[^\/]+)\/job\/(?<repo>[^\/]+)\/job\/(?<pr>[^\/]+)\/(?<run>[^\/]+)\/pipeline-graph\//;
  21.  
  22. const match = url.match(regex);
  23.  
  24. if (match) {
  25. const { organizationId, repo, pr, run } = match.groups;
  26.  
  27. const hydratedUrl = parameterizedUrl
  28. .replace(':organizationId', organizationId)
  29. .replace(':repo', repo)
  30. .replace(':pr', pr)
  31. .replace(':run', run);
  32.  
  33. if (!shouldConfirm) {
  34. const div = document.createElement('div')
  35.  
  36. div.style.position = 'fixed'
  37. div.style.backgroundColor = '#ffffffee'
  38. div.style.display = 'grid'
  39. div.style.gap = '0.5rem'
  40. div.style.placeContent = 'center'
  41. div.style.top = 0
  42. div.style.bottom = 0
  43. div.style.left = 0
  44. div.style.padding = '1rem'
  45. div.style.right = 0
  46. div.style.zIndex = 9999
  47. div.style.transition = 'all 0.3s'
  48.  
  49. const text = document.createElement('div')
  50.  
  51. text.innerText = 'Redirecting to Blue Ocean...'
  52.  
  53. div.appendChild(text)
  54.  
  55. const button = document.createElement('button')
  56.  
  57. const timeout = setTimeout(() => {
  58. window.location.href = hydratedUrl
  59. }, 1_500)
  60.  
  61. button.onclick = () => {
  62. clearTimeout(timeout)
  63. div.style.opacity = 0
  64.  
  65. setTimeout(() => {
  66. div.remove()
  67. }, 300)
  68. }
  69.  
  70. button.innerText = 'Cancel'
  71.  
  72. div.appendChild(button)
  73. document.body.appendChild(div)
  74. button.focus()
  75. } else if (confirm('Redirect to Blue Ocean?')) {
  76. window.location.href = hydratedUrl;
  77. }
  78. } else {
  79. console.log("No match found");
  80. }
  81. })();