Hudson / Jenkins Report Only Consecutive Failures

I use Jenkins to run Selenium tests in monitoring mode. Errors are often temporary (timeouts, etc.). I escalate the execution of projects after a failure with the Naginator plugin, and the next build usually goes through.

Thus, I am looking for the opportunity to use a failure counter that will allow me to send a notification only when the test fails n times in a row. Do you know how to do this?

+4
source share
5 answers

Daniel, I believe your best bet is the script itself. I had a similar problem , and I came up with a three-line solution myself without any experience with Java / Groovy.

First of all, you need a way to determine that the assembly failed. See My problem for a solution.

Secondly, you need to keep the number of failed collections somewhere. The file in the project workspace is the obvious place. Use this snippet as a base:

def f = new File(manager.build.getWorkspace().getRemote() + '/GroovyFailedBuildsCount.txt') f.createNewFile() f.write(text) 

And thirdly, you need to send an email. At the top of my head, you can note that the first failed builds are unstable, and when the limit is reached, mark the build as unsuccessful and add the email-ext plugin to send email notifications only in case of failures.

Groovy getting started helped me.

+5
source

Alternative implementation:

  • Use the Disable Job plugin to disable a controlled job after a certain number of crashes.
  • Create a monitoring task that checks if the monitored task is disabled. If the job is disabled, then fail monitoring and send an email.
  • (optional) Turn off the monitoring task so that it does not send you emails.

This has a happy side effect, also notifying you if someone manually shuts down your work.

To get a list of disabled jobs whose title contains a "header filter":

 curl -sS http://jenkins.example.com/api/json \ | jq '.jobs[] | select(.name | contains("title filter")) | select(.color=="disabled") | .name' 
+1
source

Jenkins notice only about sequential erratic

With Jenkins v. 2.65 and Groovy Plugin Postbuild v. 2.3.1

  • Install the Jenkins notification plugin (mail / slate, etc.) to send messages only if the assembly fails.

  • Add this Groovy code as a Postbuild action to work

     // debugging: // manager.build.@result = hudson.model.Result.SUCCESS; final int threshold = 2; String jobName = manager.build.project.name; def f = new File('/tmp/' + jobName + '_GroovyUnstableBuildsCount.txt'); // debugging: // manager.createSummary("info.gif").appendText('path: ' + f.toString(), false, false, false, "red") if(!f.exists()){ // file don't exists f.createNewFile(); } // debugging: // String fileContent = f.text; // manager.createSummary("info.gif").appendText('fileContent: ' + fileContent, false, false, false, "red") if (manager.build.result.isBetterOrEqualTo(hudson.model.Result.SUCCESS)) { f.write("0"); } else if (manager.build.result == hudson.model.Result.UNSTABLE) { int oldValue = 0; if(f.text != null && !f.text.empty && f.text != ''){ oldValue = f.text.toInteger(); } int newValue = oldValue + 1; if(newValue > threshold){ // trigger send message // set build to fail manager.build.setResult(hudson.model.Result.FAILURE); f.write("0"); // reset counter } else { // increase count f.write(newValue.toString()); } } 
+1
source

The email-ext plugin allows you to send emails when the build status is "Failed" for two or more collections. Unfortunately, he will send you an e-mail every time after that. A groovy script may still be

0
source

You can use the jenkins Editable Email Notification plugin, and in the advanced settings you will have the fail-X option, in which you can specify how many failures you need to send by email. Older versions of Jenkins may not help with this. So you can use the following PRESEND SCRIPT in an editable email notification

 try { //used try catch because NAGINATOR_COUNT will be a undefined property for first build cancel = true if ($NAGINATOR_COUNT && $NAGINATOR_COUNT == 2) { //where after 2nd retry it will trigger email cancel = false } } catch (e) { cancel = true } 

http://jenkins-ci.361315.n4.nabble.com/Email-only-after-all-retries-fail-td4713630.html

0
source

All Articles