Why does my Groovy script run in the Jenkins Script Console but not as a Groovy Postbuild Script?
<p>This script runs in the my Jenkins Script Console but not as Groovy Postbuild script.</p>

<pre><code>job = hudson.model.Hudson.instance.getItem("MyJob")
build = job.getLastBuild()
action = build.getAction(jenkins.metrics.impl.TimeInQueueAction.class)
</code></pre>

<ul>
<li>Jenkins ver. 1.625.3</li>
<li>Groovy Postbuild plugin v 2.0</li>
</ul>

<p>It fails on the last line. I have the Metrics Plugin installed v 3.0.11 which <strong><em>should</em></strong> give me access to the metrics library.</p>

<p>It seems like I have to somehow import the TimeInQueueAction class int the plugin, even the Script Console can access it.</p>

<p>Can you help?</p>

<p>EDIT: the error I get:</p>

<pre><code>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
</code></pre>