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
Kotie Smit 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

What is PKI

PKI = Public Key Infrastructure
(Resource) Method of asserting the identity and validity of a person (or entity) that you have not previously met or interacted.

It use of certificates containing identifying information and public keys (these certificates are more properly called X.509 certificates).

PKI accomplishes this by defining a central authority who is mutually trusted by all users of the system.