Skip to content

Commit

Permalink
Fixed buildFailureMessage.groovy (#1902)
Browse files Browse the repository at this point in the history
Signed-off-by: pgodithi <[email protected]>
  • Loading branch information
prudhvigodithi authored Apr 4, 2022
1 parent 6ad1b9d commit 0f02c6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions vars/buildFailureMessage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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"]
}
Expand Down

0 comments on commit 0f02c6f

Please sign in to comment.