此脚本在我的Jenkins脚本控制台中运行,但不在Groovy Postbuild脚本中运行。
job = hudson.model.Hudson.instance.getItem("MyJob")
build = job.getLastBuild()
action = build.getAction(jenkins.metrics.impl.TimeInQueueAction.class)
最后一行失败了。我安装了3.0版本的Metrics插件, 让我可以访问指标库。
似乎我必须以某种方式在插件中导入TimeInQueueAction类,即使脚本控制台也可以访问它。
你能帮忙吗?
编辑:我得到的错误:
5:03:40 groovy.lang.MissingPropertyException: No such property: jenkins for class: Script1
15:03:40 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
15:03:40 at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
15:03:40 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
15:03:40 at Script1.run(Script1.groovy:3)
15:03:40 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:580)
15:03:40 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:618)
15:03:40 at groovy.lang.GroovyShell.evaluate(GroovyShell.java:589)
15:03:40 at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:166)
15:03:40 at org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder.perform(GroovyPostbuildRecorder.java:355)
15:03:40 at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
15:03:40 at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:785)
15:03:40 at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:726)
15:03:40 at hudson.model.Build$BuildExecution.post2(Build.java:185)
15:03:40 at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:671)
15:03:40 at hudson.model.Run.execute(Run.java:1766)
15:03:40 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
15:03:40 at hudson.model.ResourceController.execute(ResourceController.java:98)
15:03:40 at hudson.model.Executor.run(Executor.java:408)
15:03:41 Finished: SUCCESS
答案 0 :(得分:0)
事实证明,将插件从2.0升级到2.3.1就可以了。