Last active
August 29, 2015 14:12
-
-
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.
This file contains hidden or 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
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