I have an array and a function.
Function calls context.sh and executes shell command with variable I want to pass (next from array in this loop).
Target:
- Grep file, use item from array every loop
- If string is not empty (returns a value from shell script) print line with message and error
- Export value 'true' to variable called 'errors found'.
def grepLogs(String) {
def errorsFound = false
List<String> list = new ArrayList<String>()
list.add("some-exclude")
list.add("anotherone")
list.add("yes")
for (String item : list) {
System.out.println(item)
context.sh "errorFinder=$(cat logfile.log | egrep 'error|ERROR'| grep -v ${list()})"
if (errorFinder) {
println "Errors in log file " + errorFinder
errorsFound = true
}
}
println "No errors found."
}
So far I cannot manage to make it check every item from array and change the value. How do I implement this?