[英]Jenkins Plugin to list total number of jobs, total number of build failure
Am looking for any Plugin from which I can pull the data which contains total number of jenkins jobs, total number of build failure happened periodically.我正在寻找任何插件,我可以从中提取包含 jenkins 作业总数的数据,构建失败的总数定期发生。
Edit 1: Getting below error referring this method List Jenkins job build detials for last one year along with the user who triggered the build编辑 1:参考此方法出现以下错误列出 Jenkins 过去一年的作业构建详细信息以及触发构建的用户
error:错误:
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
edit 2:编辑2:
Am running the script as "Execute system Groovy Step" in build section of freestyle job.我在自由式作业的构建部分将脚本作为“执行系统 Groovy 步骤”运行。
Below image for your reference.下图供您参考。
enter image description here在此处输入图像描述
and at the same time I have tried running the same script at manage jenkins-> script console part as well.同时我也尝试在管理 jenkins-> 脚本控制台部分运行相同的脚本。
Still getting below error.仍然低于错误。
error:错误:
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)
Please let me know if am missing something here.如果我在这里遗漏了什么,请告诉我。
I made a code to obtain a "Resume" of all Jobs with FAILURES, SUCCESSES AND UNSTABLES, each Job and Total of all Jobs.我编写了一个代码来获取所有具有失败、成功和不稳定的工作的“简历”,每个工作和所有工作的总数。 Also you can insert number of days, by default will get all Jobs in 1 day and check numbers of FAILURES, SUCCESSES AND UNSTABLES.您还可以插入天数,默认情况下将在 1 天内获取所有作业并检查失败、成功和不稳定的数量。
This is a pipeline.这是一个管道。
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='\033[1;31m'
def BLUE='\033[1;34m'
def GREEN='\033[1;32m'
def YELLOW='\033[1;33m'
def ORANGE='\033[0;33m'
def MAGENTA='\033[1;35m'
def PURPLE='\033[1;35m'
def CIAN='\033[1;36m'
def NC='\033[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
I use XTERM to add color to your Terminal, if you dont use it, please delete that "{}" brackets and delete "// Bash colors:" part.我使用 XTERM 为您的终端添加颜色,如果您不使用它,请删除“{}”括号并删除“// Bash colors:”部分。
Hope you understand me.希望你能理解我。
Franco佛朗哥
EDIT: You will have to give some permission in "<URL_OF_YOUR_JENKINS>/jenkins/scriptApproval/"编辑:您必须在“<URL_OF_YOUR_JENKINS>/jenkins/scriptApproval/”中授予一些权限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.