Problem with accessing Jenkins items in onOffline() call from ComputerListener

26 views
Skip to first unread message

t4k30ff

unread,
Dec 2, 2021, 5:07:53 AM12/2/21
to Jenkins Developers
Hello everyone,

I am using the onOffline callback method from the ComputerListener class to receive information about the existing jobs in my Jenkins instance. The problem i face is that on my personal installation (installed on my pc, not the plugin dev suite) of Jenkins, the Jenkins.get().getAllItems(Job.class) aswell as Jenkins.get().getAllItems() would have the size 0 (so they are empty).
On the other hand when i was testing the plugin on my plugin-dev suite (the jenkins instance you would start in the project with mvn hpi:run) it was working...

Is this a bug? Or am i missing something?
Or was this mentioned anywhere before?

The Jenkins-version of the plugin-dev suite: 2.277.1
Jenkins version on my pc: 2.303.1

Thanks for any advice in advance!
Regards

Jesse Glick

unread,
Dec 2, 2021, 9:44:34 AM12/2/21
to jenkin...@googlegroups.com
On Thu, Dec 2, 2021 at 5:07 AM t4k30ff <valentin.r...@gmail.com> wrote:
Is this a bug?

I believe so. Most likely the thread calling `onOffline` is running under some user’s authentication (or “anonymous”) and that user lacks read permission to some jobs. Add a `Thread.dumpStack();` call to your listener to find out. If the stack trace starts with some HTTP handler thread, then this is likely the culprit. The workaround would be to wrap your call to `getAllItems` in `ACL.as(ACL.SYSTEM)` (`ACL.as2(ACL.SYSTEM2)` with a newish Jenkins baseline); if that indeed fixes the problem, you should file a bug for Jenkins core.

Feel free to offer a fix too; basically any call to any listener method ought to be run as `SYSTEM[2]` if there is any chance the calling thread might otherwise have been using a non-system identity. (It is also good practice to make calls to listener methods catch and log exceptions, so that bugs in listener implementations do not break other functionality.)
Reply all
Reply to author
Forward
0 new messages