Last active
June 16, 2019 19:14
-
-
Save O5ten/231404c49200a6153d3f802410ddefe4 to your computer and use it in GitHub Desktop.
Example jenkinsfile to test some arbitrary output in the log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
parameters { | |
string(name: 'stuffToCheck', defaultValue: 'Test Failure!,Some Other Failure!', desription: 'CSV of stuff to check in the build-log') | |
} | |
stages { | |
stage('The thing'){ | |
steps { | |
echo 'Test Failure!' | |
echo 'Some Other Failure!' | |
} | |
} | |
} | |
post { | |
always { | |
script { | |
def stuffToCheck = params.stuffToCheck.tokenize(',') | |
def logEntries = currentBuild.rawBuild.getLog(Integer.MAX_VALUE) | |
def violatingRows = logEntries.findAll { entry -> | |
stuffToCheck.any { thing -> entry.contains(thing) } | |
} | |
if(violatingRows) { | |
error """ | |
failing build because of these rows: | |
====================== | |
${violatingRows.join('\n')} | |
""" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment