2

I want to disable a job if it fails three or more times. I found this solution to disable it immediately. But I want to wait three times.

Community
  • 1
  • 1
jan
  • 2,741
  • 4
  • 35
  • 56

1 Answers1

5

You can get the previous result from build.previousBuild. For example:

def failingForAtLeast(build, n) {
    def failed = build.result.isWorseThan(hudson.model.Result.SUCCESS );
    if( n <= 1 ) {
        return failed;
    } else if ( failed && build.previousBuild != null) {
        return failingForAtLeast(build.previousBuild, n-1);
    } else {
        return false;
    }
}

if ( failingForAtLeast(manager.build, 3) ) {
  manager.build.project.disabled = true
}
Piotr Praszmo
  • 17,928
  • 1
  • 57
  • 65