-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins-color-output.js
194 lines (168 loc) · 5.86 KB
/
jenkins-color-output.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// ==UserScript==
// @name Jenkins colored console
// @namespace http://www.sapo.pt/
// @description Parses the build log output
// @include https://*/job/*/console*
// @version 2.1
// @grant none
// ==/UserScript==
addGlobalStyle(
"pre.console-output.parsed { background-color: #333 }" +
"div.console-debug { color: purple }" +
"div.console-minor { color: #555 !important }" +
"div.console-faded { color: #888 !important }" +
"div.console-normal { color: #ddd }" +
"div.console-important { color: #C2E812 }" +
"div.console-warning { color: orange }" +
"div.console-success { color: #13CD48 }" +
"div.console-error { color: #ff4c4c }" +
"div.console-hidden { display: none }" +
"div.console-stage, " +
"div.console-stage span { background-color: #2E5A61 !important; padding: 20px 10px !important; color: white !important; margin: 5px 0; }"
); // 58A4B0 373F51
var timer = setInterval(parse_console_blocks, 150);
var foundBlocksTimeout = 10;
var patterns = [
// stages
{ stage: /\[Pipeline\] { \(/ },
{ hidden: /\[Pipeline\]/ },
// git logs
{ minor: /> git / },
{ minor: /The recommended git tool/ },
{ minor: /^Running in Durability level/ },
{ minor: /span> *Running as/i },
{ minor: /^Attempting to resolve/ },
{ minor: /^Found match/ },
{ faded: /^Fetching upstream/ },
{ minor: /^Fetching changes/ },
{ minor: /^using/i },
{ minor: /^avoid /i },
{ faded: /^cloning /i },
{ faded: /span> *cloning /i },
{ faded: /^Commit message/ },
{ faded: /^Checking out Rev/ },
{ minor: /^Loading library/ },
{ minor: /Obtained Jenkinsfile/ },
{ minor: /^Push event to/ },
{ minor: /^Seen/ },
{ minor: /ssh[-_]agent/i},
{ minor: /ssh[-_]add/i},
{ minor: /ssh[-_]auth/i},
{ minor: /Identity added/ },
// docker builds
{ minor: /The push refers to repository/ },
{ minor: /: Pulling from/ },
{ minor: /: Pulling fs layer/ },
{ minor: /: Already exists/ },
{ minor: /: Layer already exists/ },
{ minor: /: Preparing/ },
{ minor: /: Waiting/ },
{ minor: /: Verifying/ },
{ minor: /: Pushed/ },
{ minor: /: (Download|Pull) complete/ },
{ minor: /Digest: sha/ },
{ minor: /\) Installing / },
{ minor: /\) Purging / },
{ minor: /\$ docker top/ },
{ minor: /\$ docker stop/ },
{ minor: /\$ docker rm/ },
{ minor: /span> *avoid /i },
{ minor: /span> *fetching /i },
{ minor: /span> *using /i },
{ minor: /span> *collecting /i },
{ minor: /span> *downloading /i },
{ minor: /span> *Getting requirements / },
{ minor: /span> *Preparing wheel / },
{ minor: /span> *Building wheels / },
{ minor: /span> *Installing build dep/ },
{ minor: /^Step [0-9]+/ },
{ minor: /^ ---> / },
{ minor: /^fetch / },
{ minor: /^OK: / },
{ minor: /Removing intermediate container/ },
{ minor: / digest: sha/ },
// java/jenkins stack trace
{ faded: /at [a-z_]+\.[a-z]+.+\(/ },
{ minor: /DescribableModel/ },
{ warning: /at .+WorkflowScript:\d+/ },
{ warning: /at .+\.groovy:\d+/ },
{ warning: /Caused: / },
{ error: /java.lang.ClassCastException/ },
// pip logs
{ minor: /Created wheel for/ },
{ minor: /Building wheel for/ },
{ minor: /Stored in directory/ },
// generic logs
{ faded: /INFO/ },
{ faded: /Info/ },
{ minor: /WARNING abort infinite/ },
{ warning: /warning/i },
{ error: /error/i },
{ success: /^successfully/i },
{ important: /span> \+ / },
{ important: /span>\+ / },
{ minor: /\[htmlpublisher\]/ },
{ warning: /skipped due to/ },
{ minor: /\[WS-CLEANUP\]/ },
{ faded: /Post stage/ },
{ minor: /Slack Send Pipeline step running/ },
{ minor: /GitHub has been notified/ },
{ success: /Finished: SUCCESS/ },
{ error: /Finished: FAILURE/ }
];
function parse_console_blocks() {
var consoleBlocks = document.querySelectorAll("#main-panel>pre.console-output:not(.parsed), #out pre:not(.parsed)");
var foundBlocks = consoleBlocks.length > 0;
if(foundBlocks) {
foundBlocksTimeout = 20;
} else if(--foundBlocksTimeout <= 0) {
//clearInterval(timer);
}
consoleBlocks.forEach(parse_console_block);
function parse_console_block(block) {
console.log("Processing text block", block);
block.classList.add("parsed");
var lines = block.innerHTML.split("\n");
var html = [];
var currentLine = 0;
parse_block_chunk();
function parse_block_chunk() {
for(var i = 0; i < 20; ++i, ++currentLine) {
if(currentLine >= lines.length) {
block.innerHTML = html.join("");
return;
}
var line = lines[currentLine];
var cssClass = select_class(line);
if (cssClass == "debug") {
console.log(line);
}
var indentMatch = /^(\s*)(.*)/.exec(line);
html.push(
"<div class='console-"+cssClass+"' style='padding-left: "+indentMatch[1].length+"ex'>" +
indentMatch[2] +
"</div>");
}
setTimeout(parse_block_chunk, 0);
}
}
function select_class(line) {
for(var i = 0; i < patterns.length; ++i) {
for(var type in patterns[i]) {
var pattern = patterns[i][type];
if(pattern.test(line)) {
return type;
}
}
}
return "normal";
}
}
function addGlobalStyle(css) {
var head = document.getElementsByTagName('head')[0];
if (!head) { return; }
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}