2014-01-15 70 views
2

我使用groovy jsonBuilder與jenkins中的groovy post build插件發生間歇性堆棧溢出錯誤。我會說,下面的代碼約25%的時間工作,其他75%的時間失敗。任何想法可能導致這種情況?錯誤的第一部分在下面。謝謝。Jenkins的groovy jsonBuilder發生間歇性堆棧溢出錯誤

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 
+0

聽起來像你的一個元素本身...你能記錄輸入,看看哪一個是導致崩潰? –

+0

嘗試更改'manager.build.timestamp'到'manager.build.timestamp.toString()' –

+0

當然,我一直無法讓它失敗。將toString()添加到時間戳記給了我JSON輸出中的這一點: 「build_timestamp」:「java.util.GregorianCalendar [time = 1389797077000,areFieldsSet = true,areAllFieldsSet = true,lenient = true,zone = sun.util .calendar.ZoneInfo [ID = \ 「美/東\」,偏移量= -18000000,dstSavings = 3600000,useDaylight = TRUE,轉換= 235,lastRule = java.util.SimpleTimeZone中的[ID = US /東歐,偏移量= -18000000 ,startDayOfWeek = 1,startTime = 7200000,startTimeMode = 0,endMode = 3,endMonth = 10,endDay = 1,...,dstSavings = .. – JamesE

回答

2

這通常是由具有內部參照本身複雜對象,這導致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') 

日曆格式化爲日期/時間字符串

手指交叉!