Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

groovy.lang.MissingPropertyException: No such property: manager for class: Script1

I am trying to invoke Groovy inside Hudson (using groovy plugin) to get some properties for our build. But I am getting this exception:

groovy.lang.MissingPropertyException: No such property: manager for class: Script1

I get this with the following line:

def buildNUmber = manager.build.number

This happens when I run as an inline command within Jenkins as well as using a script:

I tried the solution below, but it fails during the declaration itself (line two):

Binding binding = new Binding();
binding.setVariable("manager", manager);
GroovyShell shell = new GroovyShell(binding);
shell.evaluate(new File("d:/dev/others/hudson/userContent/ScriptStuff.groovy").text);

The above is run using: Groovy command. And when I run the build it errors and complains about the line - binding.setVariable("manager", manager);

When I use the Groovy script file, then it complains about:

 def buildNumber = manager.build.number

Both errors are :

groovy.lang.MissingPropertyException: No such property: manager for class: Script1

Tried everything mentioned in this thread as well:

I am using Hudson 2.2.1 and Groovy 2.1.3. What could be wrong?

like image 742
Aneesh Vijendran Avatar asked Apr 18 '13 13:04

Aneesh Vijendran


3 Answers

manager is provided by certain Groovy script plugins, but not all. To make your script generic, use the Jenkins/Hudson API instead:

import hudson.model.*

def build = Thread.currentThread().executable
def buildNumber = build.number
...
like image 139
Craig Avatar answered Nov 15 '22 01:11

Craig


Just in case it helps, if you are using the 'Execute System Groovy Script', you don't need to use the 'manager' variable. This worked for me -

def workspace = build.getEnvVars()["WORKSPACE"]
like image 10
mmukhe Avatar answered Nov 14 '22 23:11

mmukhe


One of the reasons groovy.lang.MissingPropertyException: is thrown when you are using a variable outside of its scope or you haven't defined that variable.

like image 9
Maverick Avatar answered Nov 15 '22 00:11

Maverick