Jenkins插件列出作业总数、构建失败总数



我正在寻找任何插件,我可以从中提取数据,其中包含jenkins作业的总数,周期性发生的构建失败的总数。

编辑1:获取以下错误引用此方法列出詹金斯最近一年的工作构建详细信息以及触发构建的用户

错误:

Building on the built-in node in workspace /data-1/ondotapps/jenkins/workspace/Finding overall build details
Job Name: ( # builds: last 365 days / overall )  Last Status
Number | Trigger | Status | Date | Duration
ERROR: Build step failed with exception
groovy.lang.MissingPropertyException: No such property: Jenkins for class: Script1
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:66)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:310)
at Script1.run(Script1.groovy:7)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:574)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:612)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:583)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:440)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:377)
at hudson.plugins.groovy.SystemGroovy.run(SystemGroovy.java:95)
at hudson.plugins.groovy.SystemGroovy.perform(SystemGroovy.java:59)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:816)
at hudson.model.Build$BuildExecution.build(Build.java:199)
at hudson.model.Build$BuildExecution.doRun(Build.java:164)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:524)
at hudson.model.Run.execute(Run.java:1897)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:442)
Build step 'Execute system Groovy script' marked build as failure
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE

编辑2:

正在以";执行系统Groovy步骤";自由式工作的构建部分。

下图供您参考。

在此处输入图像描述

同时,我尝试在manage-jenkins运行相同的脚本->脚本控制台部分。

仍低于错误。

错误:

Job Name: ( # builds: last 365 days / overall )  Last Status
Number | Trigger | Status | Date | Duration
groovy.lang.MissingPropertyException: No such property: instance for class: Script1
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:66)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:310)
at Script1$_run_closure1.doCall(Script1.groovy:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)

如果我遗漏了什么,请告诉我。

我制作了一个代码来获得一个"简历"在所有失败、成功和不稳定的工作中,每个工作和所有工作的总数。此外,您还可以插入天数,默认情况下,将在一天内获得所有作业,并检查失败、成功和不稳定的数量。

这是一条管道。

properties([disableConcurrentBuilds(),buildDiscarder(logRotator(artifactDaysToKeepStr: '1', artifactNumToKeepStr: '', daysToKeepStr: '1', numToKeepStr: '')),pipelineTriggers([cron('H 1 * * *')]),parameters([string(defaultValue: 'NO', name: 'SHOW_LIST'),string(defaultValue: '1', name: 'DAYS'),string(defaultValue: '.*', name: 'FILTER',description:'''Use ".*" for all jobs 
''')])])

@NonCPS
def Funcion(){

int value = env.DAYS as Integer    
def jobNamePattern =env.FILTER   
def daysBack = value  
def timeToDays = 24*60*60*1000 
def myList= ""
def C_Fail_T=0
def C_Unst_T=0
def C_Succ_T=0 

// Bash colors:
def RED='33[1;31m'
def BLUE='33[1;34m'
def GREEN='33[1;32m'
def YELLOW='33[1;33m'
def ORANGE='33[0;33m'
def MAGENTA='33[1;35m'
def PURPLE='33[1;35m'
def CIAN='33[1;36m'
def NC='33[0m' 

def TOTAL= Jenkins.instance.allItems.findAll() {

it instanceof Job && it.fullName.matches(jobNamePattern) 
}.each {job ->

def builds = job.getBuilds().byTimestamp(System.currentTimeMillis() - daysBack*timeToDays, System.currentTimeMillis())

// individual build details
def C_Fail=0
def C_Unst=0
def C_Succ=0

//if(job.fullName.equals(excluid.findAll { it > job.fullName.toString() }) )
//{
//}

builds.each {def build ->
if(build.result == hudson.model.Result.FAILURE) { C_Fail=C_Fail+1} 
if(build.result == hudson.model.Result.UNSTABLE){ C_Unst=C_Unst+1}
if(build.result == hudson.model.Result.SUCCESS) { C_Succ=C_Succ+1}
}
C_Fail_T = C_Fail_T + C_Fail
C_Unst_T = C_Unst_T + C_Unst
C_Succ_T = C_Succ_T + C_Succ
myList= myList+ "n" + (job.fullName + ' ( ' + builds.size() + ' / ' + job.builds.size() + ' )  ' + "in " + daysBack + " day/s " + "LAST STATUS: "+job.getLastBuild()?.result +" | "+RED+ "FAILURE: "+C_Fail +ORANGE+ " UNSTABLE: " + C_Unst +GREEN+ " SUCCESS: " + C_Succ+NC) 
// individual build details
//builds.each { build ->
//  println '   ' + build.number + ' | ' + build.getCauses()[0].getShortDescription() + ' | ' + build.result + ' | ' + build.getTimestampString2() + ' | ' + build.getDurationString()
//}
}
job=null
build=null
builds=null
jobNamePattern=null
if(env.SHOW_LIST=="YES"){
println(myList)
}
println("RESUME Jobs in "+DAYS+" day/s "+GREEN+": SUCCESS " +C_Succ_T +NC+RED+ "  FAILED "+C_Fail_T+NC+ORANGE+"  UNSTABLE " +C_Unst_T +NC)

if(C_Succ_T==0 && C_Unst_T==0 && C_Fail_T==0)
{
println("FILTER input wrong")
currentBuild.result('FAILURE')
}
}
timestamps {
withCredentials([usernamePassword(credentialsId: '501b9ef0-5c12-4b19-9cd1-1fcd87e37aec', passwordVariable: 'OS_PASSWORD', usernameVariable: 'OS_USERNAME')]) {
ansiColor('xterm') {
String repoUrl = "YOUR_REPO_IF_NEED"

node{
echo 'Clearing workspace before cloning: '
cleanWs()
// Clones the repository from the current branch name
git credentialsId: 'credentialsId', url: repoUrl
Funcion()
}

} //USER
} //XTERM
} //TIMESTAMP

我使用XTERM为您的终端添加颜色,如果您不使用它,请删除";{}";括号并删除"//Bash颜色:;部分

希望你能理解我。

Franco

编辑:你必须在"<URL_OF_YOUR_JENKINS>jenkins/scriptApproval/";

最新更新