[workflow-plugin] Computer.currentComputer() returns null

108 views
Skip to first unread message

Rafael Ribeiro Rezende

unread,
Nov 12, 2015, 9:45:16 AM11/12/15
to Jenkins Developers
I was using `Computer.currentComputer()` in my old recorder plugin and kept this part when I implemented the Workflow compatibility.

Interestingly, it works for both Freestyle and Workflow jobs when I'm running my plugin as dev (hpi:run). I debugged it just to confirm everything is as expected.
However, when I install the plugin on a Jenkins instance, the workflow builds break because that command always return null.

java.lang.NullPointerException
        at com
.bosch.cdg.jenkins.rtcpublisher.RTCPublisher.perform(RTCPublisher.java:220)
        at org
.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:64)
        at org
.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:55)
        at org
.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution.start(AbstractSynchronousStepExecution.java:34)
        at org
.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:136)
        at org
.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:98)
        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.AbstractCallSite.call(AbstractCallSite.java:108)
        at com
.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
        at
WorkflowScript.run(WorkflowScript:8)
        at
Unknown.Unknown(Unknown)
        at ___cps
.transform___(Native Method)
        at com
.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:69)
        at com
.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
        at com
.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79)
        at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun
.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java
.lang.reflect.Method.invoke(Unknown Source)
        at com
.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
        at com
.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.dispatch(CollectionLiteralBlock.java:55)
        at com
.cloudbees.groovy.cps.impl.CollectionLiteralBlock$ContinuationImpl.item(CollectionLiteralBlock.java:45)
        at sun
.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java
.lang.reflect.Method.invoke(Unknown Source)
        at com
.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
        at com
.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
        at com
.cloudbees.groovy.cps.Next.step(Next.java:58)
        at com
.cloudbees.groovy.cps.Continuable.run0(Continuable.java:145)
        at org
.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:268)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:71)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:177)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:175)
        at org
.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
        at java
.util.concurrent.FutureTask.run(Unknown Source)
        at hudson
.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:111)
        at jenkins
.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
        at java
.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java
.util.concurrent.FutureTask.run(Unknown Source)
        at java
.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java
.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java
.lang.Thread.run(Unknown Source)

This was experienced in multiple instances of Jenkins, different machines, so I don't think it's an issue specifically of my environment.
The hard part is that I cannot debug it properly, because it does not happen when using "hpi:run"...

Is it a bug? misconfiguration? or I'm not expected to use this command with workflow at all?
Why would it work with "hpi:run" but not in a standalone Jenkins?

Jesse Glick

unread,
Nov 12, 2015, 1:31:42 PM11/12/15
to Jenkins Dev
On Thu, Nov 12, 2015 at 9:45 AM, Rafael Ribeiro Rezende
<rafael...@gmail.com> wrote:
> Is it a bug? misconfiguration? or I'm not expected to use this command with workflow at all?

You should not rely on `Computer.currentComputer` inside
`SimpleBuildStep.perform`. You can get the `Node`/`Computer` from the
`FilePath workspace` (which will work for freestyle builds, too).
Looks like

https://github.com/jenkinsci/workflow-plugin/blob/master/COMPATIBILITY.md#build-steps

needs to be updated to call that out explicitly.

Rafael Ribeiro Rezende

unread,
Nov 16, 2015, 10:55:11 AM11/16/15
to Jenkins Developers
Thanks, Jesse!

workspace.toComputer().getNode()

...solves the issue!
Reply all
Reply to author
Forward
0 new messages