Search code examples
jenkinsgroovycontinuous-integrationcicd

Jenkins script cant call DiskSpaceMonitor.getFreeSpace(computer) on SlaveComputer


Trying to get the disk space for a node but running in to the following error: No signature of method: java.lang.Class.getFreeSpace() is applicable for argument types: (hudson.slaves.SlaveComputer)

Code snippet:

Computer computer = Jenkins.instance.getComputer(env.NODE_NAME)
freeSpace = DiskSpaceMonitor.getFreeSpace(computer).size

Is there casting needed? I thought SlaveComputer is a child of Computer so the method would work.


Solution

  • The actual error message is No signature of method: static hudson.node_monitors.DiskSpaceMonitor.getFreeSpace() is applicable for argument types: (hudson.slaves.SlaveComputer), static being the key word here.

    Computer computer = Jenkins.get().getComputer(env.NODE_NAME)
    def freeSpace = new DiskSpaceMonitor().getFreeSpace(computer).size