我有以下代码,我正在使用 Groovy 2.4.3 从 Jenkins 非系统 Groovy 脚本执行
private void readJsonFile() {
if (testsValid == false) {
def jsonSlurper = new JsonSlurper()
try {
println "FileReader("+jsonFileName+")"
def fr = new FileReader(jsonFileName)
println "About to slurp from FileReader "+fr
println "Class: " + fr.getClass()
tests = jsonSlurper.parse(fr)
} catch (FileNotFoundException e) {
println "Properties File Not Found: "+jsonFileName
e.printStackTrace()
} catch (IllegalArgumentException e) {
println "Illegal Argument: " + e.getCause()
e.printStackTrace()
}
}
}
但是,当我运行它时,我得到以下异常:
FileReader(/var/lib/jenkins/workspace/2TierUtmsLog2/resources/utmsdata.json)
About to slurp from FileReader java.io.FileReader@125d92c
Class: class java.io.FileReader
Caught: java.lang.IllegalArgumentException: argument type mismatch
java.lang.IllegalArgumentException: argument type mismatch
at JenkinsJsonTestDao.readJsonFile(JenkinsJsonTestDao.groovy:82)
at JenkinsJsonTestDao.readJenkinsUtmsTest(JenkinsJsonTestDao.groovy:51)
at JenkinsTestDaoIf$readJenkinsUtmsTest.call(Unknown Source)
at JenkinsTestLogger.logTestResult(JenkinsTestLogger.groovy:32)
at JenkinsTestLoggerIf$logTestResult.call(Unknown Source)
at JenkinsLog.logTest(JenkinsLog.groovy:76)
at JenkinsLog$logTest.call(Unknown Source)
at JenkinsLog.main(JenkinsLog.groovy:44)
Build step 'Execute Groovy script' marked build as failure
JsonSlurper.parse(Reader r) 方法确实需要一个 Reader,所以我不明白为什么这不起作用。我也尝试过使用 JsonSlurper.parse(String s) 方法,但得到了同样的错误。我还打印了通过 FileReader 读取的内容,它是正确的。
谁能发现我做错了什么,或者这是我遇到的另一个 Jenkins 限制。
添加了请求的信息:
jsonSlurper: groovy.json.JsonSlurper@19e733e
Print of new File(...)
{ "job": [
{
"jenkins_name": "ForceAResult-fail",
"utmsEnabled": "1",
"utmsCycleId": "1",
"utmsProejct": "Unity",
"utmsTeam": "CA-SS System Software",
"utmsTestName": "Force_a_test",
"utmsTestPlanId": "2",
"utmsTestSetId": "3",
},
{
"jenkins_name": "ForceAResult-pass",
"utmsEnabled": "1",
"utmsCycleId": "1",
"utmsProejct": "Unity",
"utmsTeam": "CA-SS System Software",
"utmsTestName": "Force_a_test",
"utmsTestPlanId": "2",
"utmsTestSetId": "3",
}
]}
Uncaught Exception: java.lang.IllegalArgumentException: argument type mismatch
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.IllegalArgumentException: argument type mismatch
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:92)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2699)
添加了 Divesh 的信息
[EnvInject] - 加载节点环境变量。建立在工作区 /var/lib/jenkins/workspace/Groovy 版本系统 Groovy 版本:1.8.9 路径:/var/lib/ccache/bin:/c4shares/auto/tools/bin:/usr/local/bin: /usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/accurev/bin:/opt/CmTools/shbin:/re/bin:/re/thirdparty_tools /java/tags/linux/Production/bin:/opt/pegasus/bin:/re/thirdparty_tools/ant/tags/Production/bin:/c4shares/auto/devutils/bin:/usr/lib/mit/bin:/ usr/lib/mit/sbin:/usr/NX/bin
GROOVY_HOME:空
[Groovy 版本] $ /var/lib/jenkins/tools/hudson.plugins.groovy.GroovyInstallation/Groovy_2.4.3/bin/groovy "/var/lib/jenkins/workspace/Groovy 版本/hudson6179818785298037506.groovy" 2015 年 9 月 24 日上午 8 点 11 分 25 秒 org.codehaus.groovy.runtime.m12n.MetaInfExtensionModule newModule 警告:模块 [groovy-nio] - 无法加载扩展类 [org.codehaus.groovy.runtime.NioGroovyMethods] 执行 Groovy 脚本 - 非系统
Divesh 的请求开始:
public java.lang.Object groovy.json.JsonSlurper.parse(byte[])
public java.lang.Object groovy.json.JsonSlurper.parse(char[])
public java.lang.Object groovy.json.JsonSlurper.parse(java.io.File)
public java.lang.Object groovy.json.JsonSlurper.parse(java.io.InputStream)
public java.lang.Object groovy.json.JsonSlurper.parse(java.io.Reader)
public java.lang.Object groovy.json.JsonSlurper.parse(java.net.URL)
public java.lang.Object groovy.json.JsonSlurper.parse(byte[],java.lang.String)
public java.lang.Object groovy.json.JsonSlurper.parse(java.io.File,java.lang.String)
public java.lang.Object groovy.json.JsonSlurper.parse(java.io.InputStream,java.lang.String)
public java.lang.Object groovy.json.JsonSlurper.parse(java.net.URL,java.lang.String)
public java.lang.Object groovy.json.JsonSlurper.parse(java.net.URL,java.util.Map)
public java.lang.Object groovy.json.JsonSlurper.parse(java.util.Map,java.net.URL)
public java.lang.Object groovy.json.JsonSlurper.parse(java.net.URL,java.util.Map,java.lang.String)
public java.lang.Object groovy.json.JsonSlurper.parse(java.util.Map,java.net.URL,java.lang.String)
public java.lang.Object groovy.json.JsonSlurper.parseText(java.lang.String)Finished: SUCCESS