Skip to content

Commit aa22da0

Browse files
authored
Added failure pattern check (#3111)
1 parent 66bae43 commit aa22da0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Jenkinsfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ def failurePatterns = [
2020
[pattern: /cat: .* No such file or directory/, description: "GPU not found"],
2121
]
2222

23+
// Given a pattern, check if the log contains the pattern and return the context.
24+
def checkForPattern(pattern, log) {
25+
def lines = log.split('\n')
26+
for (int i = 0; i < lines.size(); i++) {
27+
if (lines[i] =~ pattern) {
28+
echo "Found pattern match in log for ${pattern}"
29+
30+
// Get the two lines before and after failure.
31+
def contextStart = Math.max(0, i - 2)
32+
def contextEnd = Math.min(lines.size() - 1, i + 2)
33+
def contextLines = []
34+
for (int j = contextStart; j <= contextEnd; j++) {
35+
contextLines.add(lines[j])
36+
}
37+
38+
return [found: true, matchedLine: lines[i], context: contextLines.join('\n')]
39+
}
40+
}
41+
echo "No pattern match found in log for ${pattern}"
42+
return [found: false, matchedLine: "", context: ""]
43+
}
44+
2345
class Version {
2446
int major, minor, patch
2547
@Override

0 commit comments

Comments
 (0)