如果失败三次或更多次,如何禁用作业?

时间:2014-07-16 16:03:23

标签: jenkins

如果作业失败了三次或更多次,我想禁用它。我发现this solution立即禁用它。但我想等三次。

1 个答案:

答案 0 :(得分:5)

您可以从build.previousBuild获取之前的结果。例如:

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
}