forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildFailureMessage.groovy
32 lines (32 loc) · 980 Bytes
/
buildFailureMessage.groovy
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
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
import com.cloudbees.groovy.cps.NonCPS
import org.apache.commons.io.IOUtils
@NonCPS
def call(){
String ERROR_STRING = "Error building"
List<String> message = []
Reader performance_log = currentBuild.getRawBuild().getLogReader()
String logContent = IOUtils.toString(performance_log)
performance_log.close()
performance_log = null
logContent.eachLine() { line ->
line=line.replace("\"", "")
//Gets the exact match for Error building
def java.util.regex.Matcher match = (line =~ /$ERROR_STRING.*/)
if (match.find()) {
line=match[0]
message.add(line)
}
}
//if no match returns as Build failed
if(message.isEmpty()){
message=["Build failed"]
}
return message
}