import hudson.FilePath
import hudson.model.*
final GROOVY_SCRIPT = "scripts/do_job_cleanup.groovy"
evaluate(new FilePath(build.workspace, GROOVY_SCRIPT).read().text)
doCleanup() // code that checks and deletes stuff we want removed
if ( nrIssues > issueThreshold ) {
println("ERROR: too many issues found")
//currentBuild.result = 'FAIL'
manager.buildFailure()
}
ERROR: Build step failed with exception
groovy.lang.MissingPropertyException: No such property: manager for class: Script1
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script1.run(Script1.groovy:501)
I have almost identical code used in another job where the Groovy is run as a postbuild step; then it works fine.