From 0f02c6fc295c14b56b516d0f5fcfdb85e1f9c24e Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Mon, 4 Apr 2022 15:01:30 -0700 Subject: [PATCH] Fixed buildFailureMessage.groovy (#1902) Signed-off-by: pgodithi --- DEVELOPER_GUIDE.md | 2 +- vars/buildFailureMessage.groovy | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 00b01166aa..db6d930a40 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -240,7 +240,7 @@ and outputs [Hello_Jenkinsfile.txt](tests/jenkins/jobs/Hello_Jenkinsfile.txt). I - To update the recorded .txt file run `./gradlew test -info -Ppipeline.stack.write=true` or update its value in [gradle.properties](gradle.properties). -- To run a specific test case, run `./gradlew test -info -tests=TestCaseClassName` +- To run a specific test case, run `./gradlew test -info --tests=TestCaseClassName` #### Tests for jenkins job Each jenkins job should have a test case associated with it. diff --git a/vars/buildFailureMessage.groovy b/vars/buildFailureMessage.groovy index a42b52a6e3..8a719289b4 100644 --- a/vars/buildFailureMessage.groovy +++ b/vars/buildFailureMessage.groovy @@ -2,18 +2,22 @@ import com.cloudbees.groovy.cps.NonCPS import org.apache.commons.io.IOUtils @NonCPS def call(){ - String ERROR_STRING = "ERROR" + String ERROR_STRING = "Error building" List message = [] Reader performance_log = currentBuild.getRawBuild().getLogReader() String logContent = IOUtils.toString(performance_log) performance_log.close() performance_log = null logContent.eachLine() { line -> - if (line.matches(".*?$ERROR_STRING(.*?)")) { - line=line.replace("\"", "") + 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"] }