Skip to main content

Jenkins error: groovy.lang.MissingPropertyException

I tried to run groovy build step and got below error. This post will describe how I solved the problem.

Caught: groovy.lang.MissingPropertyException: No such property: hudson for class: script


 
Full error message
15:51:57  Building on master
15:51:57  [workspace] $ d:\groovy-1.8.2\bin\groovy.bat -cp dom4j-1.6.1.jar D:\jenkins\jobs\Staging_ForZiv_CleanWorkspace\workspace\script.groovy
15:51:59  Caught: groovy.lang.MissingPropertyException: No such property: hudson for class: script
15:51:59  groovy.lang.MissingPropertyException: No such property: hudson for class: script
15:51:59  at script.deleteWorkspaceIfNotRunning(script.groovy:7)
15:51:59  at script$deleteWorkspaceIfNotRunning.callCurrent(Unknown Source)
15:51:59  at script.run(script.groovy:3)
15:51:59  Build step 'Execute Groovy script' marked build as failure
15:51:59  Finished: FAILURE



The script that I tried to run
deleteWorkspaceIfNotRunning ("ApolloContinuous")
deleteWorkspaceIfNotRunning ("ApolloDotNet")
deleteWorkspaceIfNotRunning ("ApolloOTAandTests")

def deleteWorkspaceIfNotRunning (jobName)
{
job = hudson.model.Hudson.instance.items.find{job -> job.name == jobName}
println ("Delete workspace for "+job.getName() + " if not under progress")

if (!job.isBuilding())
{
println ("     >>> Delete workspace for "+job.getName() + " ...")
job.doDoWipeOutWorkspace()
}
else
{
println ("     >>> Do not delete workspace for "+job.getName() + " because it is currently under progress")
}
}



The configuration (after I installed Groovy Plugin)
 
The root cause of the error and the solution
I didn't noticed but Groovy plugin added two build step types: "Execute groovy script" and "Execute system groovy script". I used by mistake the first type instead of the second.
So fix was simple - delete this step and create new step of type "Execute system groovy script"
 

Comments

JRS said…
Thanks for sharing this - I've wasted way too much time due to this mistake...
Anonymous said…
Ditto. Nice catch, thank you.
Ziv said…
Thanks
Anonymous said…
Big thanx!!
Anonymous said…
Thanks :) You have saved my Day!!
Anonymous said…
Thank you. It solved my long pending issue.
:)

Popular posts from this blog

Best freeware - XML editor

As a software developer, I open XML files all the time. I a heavy commercial XML editor. But nothing can compare to a small, thin and free XML editor like 'foxe'. A great feature is has is the alignment of long XML strings to readable XML format (Shift-F8). It help lot of times when the XML file was generated by some tool and was not readable. Homepage: http://www.firstobject.com/dn_editor.htm

SSL in pictures

Here is my summary on SSL (or as I like to call it 'SSL for dummies')