Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@guyc
Last active August 29, 2015 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guyc/b9dd19e10cadceefb2d2 to your computer and use it in GitHub Desktop.
Save guyc/b9dd19e10cadceefb2d2 to your computer and use it in GitHub Desktop.
This is a Groovy script for Jenkins that will change the first failure to a success status, subsequent failures will be reported as failures. We use this to shut up spurious failure notifications for intermittent failures while we get some false alarms from our Sahi monitoring system ironed out.
Boolean failed = manager.getResult() != "SUCCESS";
def file = new File(manager.build.getWorkspace().getRemote() + '/FailedBuildsCount.txt');
def count = 0;
if (failed) {
if (!file.exists()) {
file.createNewFile();
} else {
FileReader reader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(reader);
String line = bufferedReader.readLine();
count = Integer.parseInt(line);
}
count+=1;
file.write(String.valueOf(count));
if (count < 2) {
manager.listener.logger.println("First failure - changing result to success");
manager.addWarningBadge("First failure is forgiven");
// manager.buildSuccess(); // see https://issues.jenkins-ci.org/browse/JENKINS-12010
manager.build.@result = hudson.model.Result.SUCCESS;
}
} else {
if (file.exists()) {
file.delete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment