1

I am executing simple groovy script using scriptler jenkins plugin.

import hudson.model.Computer
import hudson.model.Node

println Computer.currentComputer().getNodeName()

If I execute this on master or any slave, giving me NullPointerException

java.lang.NullPointerException: Cannot invoke method getNodeName() on null object
        at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

Not sure what is wrong with script.

rohitkadam19
  • 1,734
  • 5
  • 21
  • 39
  • Guess it's not on an executor thread. http://javadoc.jenkins-ci.org/hudson/model/Computer.html#currentComputer() – tim_yates Apr 23 '15 at 17:12

2 Answers2

1

The code you posted can be executed only for specyfic job in "Execute system Groovy script" (it is in your job configuration).

jussuper
  • 3,397
  • 1
  • 12
  • 12
  • I have used scriptler plugin. when I execute above script in job on master getting this exception - failed - groovy.lang.MissingMethodException: No signature of method: hudson.model.Hudson$MasterComputer.getNodeName() is applicable for argument types: () values: [] – rohitkadam19 Apr 24 '15 at 08:48
0

java.lang.NullPointerException: Cannot invoke method getNodeName() on null object means for Computer.currentComputer().getNodeName() that Computer.currentComputer() returns null. As of why that is? There is not enough information to answer this

blackdrag
  • 6,413
  • 2
  • 26
  • 38
  • What change I should do in my script, so that I can get the node name of currently running job. – rohitkadam19 Apr 24 '15 at 17:52
  • your script s ok. See http://javadoc.jenkins-ci.org/hudson/model/Computer.html#currentComputer%28%29 : "Gets the current Computer that the build is running. This method only works when called during a build, such as by Publisher, BuildWrapper, etc. Returns: the Computer associated with Executor.currentExecutor(), or (consistently as of 1.591) null if not on an executor thread". So I assume you are not running the script during a build, not in the executor thread, or you have not configured things properly. In any case, this would be a Jenkins question then, which I don't know much of. – blackdrag Apr 25 '15 at 04:29