forked from opensearch-project/opensearch-build-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildMessage.groovy
36 lines (36 loc) · 1.15 KB
/
buildMessage.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
33
34
35
36
/*
* Copyright OpenSearch Contributors
* 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.
*/
/** Library to search string in jenkins build log.
@param Map args = [:] args A map of the following parameters
@param args.search <required> - String to be searched in build logs.
*/
import com.cloudbees.groovy.cps.NonCPS
import org.apache.commons.io.IOUtils
@NonCPS
def call(Map args = [:]){
String QUERY_STRING = args.search
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 of the log starting with args.search
def java.util.regex.Matcher match = (line =~ /$QUERY_STRING.*/)
if (match.find()) {
line=match[0]
message.add(line)
}
}
if (message.isEmpty()) {
message = null
}
return message
}