"currentBuild" doesn't work too.I forgot to add that we are using Groovy Event Listener Plugin to publish data. So, this script is executed in 'onFinalized' method.
>>> Caught unhandled exception! No such property: currentBuild for class: script1471951099891369958697 groovy.lang.MissingPropertyException: No such property: currentBuild for class: script1471951099891369958697 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231) at script1471951099891369958697.run(script1471951099891369958697.groovy:9) at script1471951099891369958697$run.call(Unknown Source) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl.runScript(GlobalEventsPlugin.groovy:305) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl.this$3$runScript(GlobalEventsPlugin.groovy) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl$this$3$runScript.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl$this$3$runScript.callCurrent(Unknown Source) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl.safeExecGroovyCode(GlobalEventsPlugin.groovy:275) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl.this$3$safeExecGroovyCode(GlobalEventsPlugin.groovy) at sun.reflect.GeneratedMethodAccessor195.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:231) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl.safeExecGroovyCode(GlobalEventsPlugin.groovy) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl.this$3$safeExecGroovyCode(GlobalEventsPlugin.groovy) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl$this$3$safeExecGroovyCode.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl$this$3$safeExecGroovyCode.callCurrent(Unknown Source) at org.jenkinsci.plugins.globalEventsPlugin.GlobalEventsPlugin$DescriptorImpl.processEvent(GlobalEventsPlugin.groovy:219) at org.jenkinsci.plugins.globalEventsPlugin.GlobalRunListener.onFinalized(GlobalRunListener.java:54) at hudson.model.listeners.RunListener.fireFinalized(RunListener.java:232) at hudson.model.Run.onEndBuilding(Run.java:1893) at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:522) at org.jenkinsci.plugins.workflow.job.WorkflowRun.access$1000(WorkflowRun.java:107) at org.jenkinsci.plugins.workflow.job.WorkflowRun$GraphL.onNewHead(WorkflowRun.java:759) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.notifyListeners(CpsFlowExecution.java:799) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$4.run(CpsThreadGroup.java:320) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:32) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)
Then there is a bug in the plugin. It should use `ThreadLocal` or similar to ensure that a given `Script` is only used for one build at a time.