我在Jenkins实例中安装了Build Failure Analyzer插件,并且在插件中输入了许多不同的错误。有谁知道在原因相同的所有作业中是否可以获得故障总数?
例如,如果构建节点在构建期间脱机或意外测试,我有时会遇到“ ChannelClosedException”失败,我想确定这在我所有工作中发生的频率。有什么方法可以汇总此值?我想如果可以为每个作业遍历每个构建并收集检测到的“构建失败”原因,可以通过常规方法来完成。
其他人以前做过类似的事情吗?
答案 0 :(得分:1)
不是确切的答案...但是应该能够进行修改以获得您所要的内容:
Jenkins.instance.getAllItems(Job).each{
def jobBuilds=it.getBuilds()
//for each job get the things (you can limit at your convenience)
jobBuilds.each { build ->
def runningSince = groovy.time.TimeCategory.minus( new Date(), build.getTime() )
def currentStatus = build.buildStatusSummary.message
def cause = build.getCauses()[0] //we keep the first cause
def user = cause instanceof Cause.UserIdCause? cause.getUserId():""
println "Build: ${build} | Since: ${runningSince} | Status: ${currentStatus} | Cause: ${cause} | User: ${user}"
def parameters = build.getAction(ParametersAction)?.parameters
parameters.each {
println "Type: ${it.class} Name: ${it.name}, Value: ${it.dump()}"
}
}
}
答案 1 :(得分:0)
使用一些google-fu和VinDev的一些信息,我想出了以下解决方案:
// get all jobs in Jenkins
Jenkins.instance.getAllItems(Job).each {
// get all builds for each job
def jobBuilds=it.getBuilds()
//for each build, get the name and status + and failure messages
jobBuilds.each { build ->
// get the build status
def currentStatus = build.buildStatusSummary.message
// we only care about the broken builds because we want failure messages
if (currentStatus.contains("broken")) {
println "Build: ${build} | Status: ${currentStatus}"
def BFA = build.actions.find{ it instanceof com.sonyericsson.jenkins.plugins.bfa.model.FailureCauseBuildAction };
if (BFA != null) {
for (failureCause in BFA.getFoundFailureCauses()) {
println("name: " + failureCause.getName() + ", description: " + failureCause.getDescription())
}
}
}
}
}