issue setting build status from within evaluated groovy script run as system script

92 views
Skip to first unread message

monger_39

unread,
Apr 12, 2019, 6:08:05 AM4/12/19
to jenkins...@googlegroups.com
Hi,

I have a job to do some cleanup in Jenkins.

the job is defined to run a "Execute system Groovy script" as build step. The code contains something like:

    import hudson.FilePath

    import hudson.model.*

    final GROOVY_SCRIPT = "scripts/do_job_cleanup.groovy"

    evaluate(new FilePath(build.workspace, GROOVY_SCRIPT).read().text)


and within the script:

    doCleanup()  // code that checks and deletes stuff we want removed

    if ( nrIssues > issueThreshold ) {

       println("ERROR: too many issues found")

       //currentBuild.result = 'FAIL'

       manager.buildFailure()

   }

During cleanup issues may be found; if we found too many, I want to set status of the job to unstable or even fail, depending on some threshold.

Whatever I try, I always get an error when trying to set the status:

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.


Why not here ??

thx, M.




Reply all
Reply to author
Forward
0 new messages