我需要获取从当前脚本执行时间开始在过去 24 小时内成功运行的作业列表。目前我只得到今天约会成功的工作,但我正在寻找最后 24 小时的工作,这可能是最后几天的工作,也可能在 24 小时内。
已经编写了一个脚本并获得了当前的结果,但不是 24 小时
import hudson.model.*
Date date = new Date()
String present = date.format("MM-dd-yyyy")
def str_view = "GitLab_jobs"
def view = Hudson.instance.getView(str_view)
def successfulJobs = view.getItems().findAll {
job - > job.lastBuild != null && job.lastBuild.result == hudson.model.Result.SUCCESS && !job.name.contains("maintenance")
}
def faildJobs = view.getItems().findAll {
job - > job.lastBuild != null && job.lastBuild.result == hudson.model.Result.FAILURE && !job.name.contains("maintenance")
}
def disabledJob = view.getItems().findAll {
job - > job.disabled == true && !job.name.contains("maintenance")
}
def enabledJob = view.getItems().findAll {
job - > job.disabled != true && !job.name.contains("maintenance")
}
println "Total jobs: " + view.getItems().size + " Successful: " + successfulJobs.size +
" Failed: " + faildJobs.size + " Enabled jobs: " + enabledJob.size + " Disabled jobs: " + disabledJob.size
println "Current Successful job Today:"
successfulJobs.each {
job - > printInfo(job)
}
def printInfo(job) {
Date date = new Date()
String datePart = date.format("MM-dd-yyyy")
String timePart = date.format("HH:mm:ss")
x = "${datePart}"
y = "${job.lastBuild.getTime().format("
MM - dd - yyyy ")}"
if ("$x" == "$y") {
println "Job: ${job.name} build on ${job.getAssignedLabelString()}, " +
"Date ${job.lastBuild.getTime().format("
MM - dd - yyyy ")}, is disabled : ${job.disabled}"
}
}