Is there a plugin to fail a build if a pattern occurs on the console output?
For example:
Build Action - success
Build Action - success
Build Action - error_pattern
Build Action - success
Let's assume that the Jenkins build process does not fail the build on error_pattern, I need to have an external fail trigger of some sort.
Looking for a solution to fail the build during, not a post build task.
The Build Failure Analyzer Jenkins plugin analyzes the causes of failed builds and presents the causes on the build page. It does this by using a knowledge base of build failure causes maintained from scratch.
To retry a Jenkins job, you can use the Naginator plugin. Simply install the plugin, and then check the Post-Build action "Retry build after failure" on your project's configuration page. If the build fails, it will be rescheduled to run again after the time you specified.
I've used this answer as the basis of a pipeline script. In the "Build" stage I have two parallel sub-stages - one of them is doing the actual build and outputting to a log, whilst the other sub-stage is grepping the same log. I've negated the exit code (! grep
) so that it'll error when the "ERROR:" string is found. Thanks to the failFast
setting, this will cause the whole "Build" stage to fail as soon as the string is found. There's an extra grep
at the end of the first sub-stage, in case an error was produced right at the end.
I'm tracking the build status with a variable (BUILD_COMPLETE
).
pipeline {
agent {
label 'master'
}
environment {
BUILD_COMPLETE = false
}
stages {
stage('Build') {
failFast true
parallel {
stage('Building') {
steps {
sh 'echo foo | tee output.log'
sleep 5
sh 'echo bar | tee -a output.log'
sleep 5
sh 'echo ERROR: baz | tee -a output.log'
sleep 5
sh 'echo qux | tee -a output.log'
sleep 5
sh '! grep "^ERROR:" output.log'
script {
BUILD_COMPLETE = true
}
}
}
stage('Monitoring the logs') {
steps {
script {
while (BUILD_COMPLETE != true) {
sh '! grep "^ERROR:" output.log'
sleep 1
}
}
}
}
}
}
}
}
You should try the Post Build Task plugin. You can search for a pattern and then launch a script.
edit: There is also Text finder plugin, looks better for your problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With