Skip to content

Instantly share code, notes, and snippets.

@O5ten
Last active June 16, 2019 19:14
Show Gist options
  • Save O5ten/231404c49200a6153d3f802410ddefe4 to your computer and use it in GitHub Desktop.
Save O5ten/231404c49200a6153d3f802410ddefe4 to your computer and use it in GitHub Desktop.
Example jenkinsfile to test some arbitrary output in the log
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