groovy - 在Jenkins中,带有 groovy jsonBuilder的间歇性栈溢出错误

  显示原文与译文双语对照的内容

我使用 groovy jsonBuilder中的groovy构建插件来获取间歇性栈溢出错误。 我认为下面的代码有约 25%个时间,它的他 75%失败。 任何可能导致这一切的想法? 错误的第一部分如下。 谢谢你。


import groovy.json.*
import hudson.model.*


def projectName = manager.build.project.name
def job = manager.hudson.instance.getItem(projectName)
def scm = job.scm
def rtcStream = scm.getStreamName()
def rtcWorkspace = scm.getWorkspaceName()
def duration = manager.build.getExecutor().getElapsedTime()
def result = manager.build.result

def json = new JsonBuilder()

def root = json.build {
 build_number manager.build.number
 build_timestamp manager.build.timestamp
 build_duration duration
 build_url manager.build.url
 build_project_name projectName
 stream rtcStream
 workspace rtcWorkspace
 build_culprits manager.build.culprits
 build_result result.toString()
}

def jsonString = JsonOutput.prettyPrint(json.toString())
manager.listener.logger.println jsonString

def channel = manager.build.workspace.channel;

def fp = new hudson.FilePath(channel, manager.build.workspace.toString() +"build.json")

if(fp!= null) {
 manager.listener.logger.println"Getting ready to write build.json"
 fp.write(jsonString, null);//writing to file
 manager.listener.logger.println"Done writing build.json"
}

错误:


FATAL: null
java.lang.StackOverflowError
 at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:72)
 at sun.reflect.GeneratedMethodAccessor5636.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:616)
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:903)
 at groovy.lang.Closure.call(Closure.java:415)
 at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:3653)
 at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2379)
 at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2396)
 at org.codehaus.groovy.runtime.dgm$83.invoke(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 at groovy.json.JsonOutput.toJson(JsonOutput.groovy:146)
 at groovy.json.JsonOutput$toJson.callStatic(Unknown Source)
 at groovy.json.JsonOutput.toJson(JsonOutput.groovy:138)
 at groovy.json.JsonOutput$toJson$3.callStatic(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:50)
 at groovy.json.JsonOutput$toJson$4.callStatic(Unknown Source)
 at groovy.json.JsonOutput$_toJson_closure2.doCall(JsonOutput.groovy:150)
 at sun.reflect.GeneratedMethodAccessor5636.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:616)
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:903)
 at groovy.lang.Closure.call(Closure.java:415)
 at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:3653)
 at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2379)
 at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2396)
 at org.codehaus.groovy.runtime.dgm$83.invoke(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 at groovy.json.JsonOutput.toJson(JsonOutput.groovy:146)
 at groovy.json.JsonOutput$toJson.callStatic(Unknown Source)
 at groovy.json.JsonOutput.toJson(JsonOutput.groovy:138)
 at groovy.json.JsonOutput$toJson$3.callStatic(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:50)
 at groovy.json.JsonOutput$toJson$4.callStatic(Unknown Source)
 at groovy.json.JsonOutput$_toJson_closure2.doCall(JsonOutput.groovy:150)
 at sun.reflect.GeneratedMethodAccessor5636.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:616)
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:903)
 at groovy.lang.Closure.call(Closure.java:415)
 at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:3653)
 at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2379)
 at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:2396)
 at org.codehaus.groovy.runtime.dgm$83.invoke(Unknown Source)
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 at groovy.json.JsonOutput.toJson(JsonOutput.groovy:146)
 at groovy.json.JsonOutput$toJson.callStatic(Unknown Source)
 at groovy.json.JsonOutput.toJson(JsonOutput.groovy:138)
 at groovy.json.JsonOutput$toJson$3.callStatic(Unknown Source)

元素的输出:


build num: 25
timestamp: java.util.GregorianCalendar[time=1389797077000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="US/Eastern",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=US/Eastern,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=0,WEEK_OF_YEAR=3,WEEK_OF_MONTH=3,DAY_OF_MONTH=15,DAY_OF_YEAR=15,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=44,SECOND=37,MILLISECOND=0,ZONE_OFFSET=-18000000,DST_OFFSET=0]
duration: 317805
url: job/Client_March_Report/25/
project: Client_March_Report
stream: Stream_Client_Development
workspace: Jenkins_Client_Workspace
culprits: []
result: FAILURE

时间: 作者:

这通常是由具有内部引用的复杂对象引起的,这导致json生成器无限循环。

查看 json.build 中的所有变量,我只能看到 manager.build.timestamp ( 这是一个 Calendar 实例) 。

你可以尝试以下选项之一:


build_timestamp manager.build.timestampString//get duration of build

或者


build_timestamp manager.build.timestampString2//Not sure

或者是


build_timestamp manager.build.timestamp.format( 'yyyy/MM/dd HH:mm:ss' )

将日历设置为日期/时间字符串

手指交叉 !

作者:
...