带有插件 RobotPublisher 的 Jenkinsfile 导致 java.lang.NullPointerException
Posted
技术标签:
【中文标题】带有插件 RobotPublisher 的 Jenkinsfile 导致 java.lang.NullPointerException【英文标题】:Jenkinsfile with Plugin RobotPublisher causes java.lang.NullPointerException 【发布时间】:2021-06-09 07:48:06 【问题描述】:我安装了 Jenkins Plugin(版本 1.6.5)直接在 Jenkins 中发布 Robot Framework 的测试结果。 机器人测试用例成功运行并创建了必要的文件。 但是如果我想将结果发布到 Jenkins,管道会抛出异常。
Jenkinsfile
pipeline
agent any
stages
stage("Run Robot")
steps
sh "robot --outputdir robot-results robot-test-cases"
script
step([$class : 'RobotPublisher',
outputPath : 'robot-results',
outputFileName : "**/output.xml",
reportFileName : '**/report.html',
logFileName : '**/log.html',
disableArchiveOutput : false,
passThreshold: 100.0,
unstableThreshold: 90.0])
管道日志异常
[...]
Output: robot-results/output.xml
Log: robot-results/log.html
Report: robot-results/report.html
[Pipeline]
[Pipeline] // stage
[Pipeline]
[Pipeline] // withEnv
[Pipeline]
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.NullPointerException
at hudson.plugins.robot.RobotPublisher.<init>(RobotPublisher.java:106)
Caused: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedConstructorAccessor584.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:330)
Caused: java.lang.IllegalArgumentException: Could not instantiate outputFileName=**/output.xml, reportFileName=**/report.html, outputPath=robot-results, logFileName=**/log.html, unstableThreshold=90.0, passThreshold=100.0, disableArchiveOutput=false for hudson.plugins.robot.RobotPublisher
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:334)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:474)
at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:409)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:329)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:272)
at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:205) at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:264)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:178)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at sun.reflect.GeneratedMethodAccessor270.invoke(Unknown Source)
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:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:160)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157) at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:158)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:162)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:132)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:132) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
Caused: java.lang.IllegalArgumentException: Could not instantiate delegate=$class=RobotPublisher, outputPath=robot-results, outputFileName=**/output.xml, reportFileName=**/report.html, logFileName=**/log.html, disableArchiveOutput=false, passThreshold=100.0, unstableThreshold=90.0 for org.jenkinsci.plugins.workflow.steps.CoreStep
[...]
【问题讨论】:
Jenkinsfile 的配置基于 SO post ***.com/a/57486465/9884812 【参考方案1】:感谢您提供插件的版本!
2.0.0 版之前的 RobotPublisher 似乎有一个错误,即otherFiles
参数(应该是可选的)是必需的,如果您省略它,则会出现此错误。
我会通过添加一个与您的任何实际文件都不匹配的otherFiles
参数来解决这个问题,例如:
otherFiles : '*.no_such_file',
【讨论】:
以上是关于带有插件 RobotPublisher 的 Jenkinsfile 导致 java.lang.NullPointerException的主要内容,如果未能解决你的问题,请参考以下文章