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
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: FAILUREThe 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
:)