IIUC you're using a Pipeline script to use the core Jenkins APIs? If so, IMHO it's going to fail ultimately. Seeing a MasterToSlaveFileCallable usage, again IIUC, from Pipeline code makes me cringe.
Pipeline is designed to be an orchestration language for your Pipeline, not offer end-user interaction with Jenkins core. If you wish to write a pipeline step and get tight integration with Jenkins internals, which can be totally legit, then you are in a case where writing a Jenkins plugin for this would likely be much better. My 2 cents. 2018-02-27 9:38 GMT+01:00 'Richard Hierlmeier' via Jenkins Users < jenkinsci-users@googlegroups.com>: > > I like to perform in a custom pipeline step some file operations on the > slave node > > The pipeline step calls the method doRemote: > > def doRemote() { > def repoDir = createFilePath("dir_in_repo") > def callable = new MasterToSlaveFileCallable<Integer>() { > > private static final long serialVersionUID = 1; > > public Integer invoke(File rootDirectory, VirtualChannel > channel) throws IOException, InterruptedException { > def count = 0 > if(rootDirectory.exists()) { > // TODO > } > return 0 > } > }; > def count = repoDir.act(callable); > } > > def createFilePath(path) { > if (env['NODE_NAME'] == null) { > error "envvar NODE_NAME is not set, probably not inside an node > {} or running an older version of Jenkins!"; > } else if (env['NODE_NAME'].equals("master")) { > return new FilePath(path); > } else { > return new FilePath(Jenkins.getInstance().getComputer(env[ > 'NODE_NAME']).getChannel(), path); > } > } > > > > Whenever the step is executed it fails with the following exception: > > [Bitbucket] Build result notified > java.lang.IllegalArgumentException: Unable to locate class file for class > customStep$1 > at hudson.remoting.Which.classFileUrl(Which.java:61) > at > hudson.remoting.RemoteClassLoader$ClassLoaderProxy.fetch4(RemoteClassLoader.java:847) > at > hudson.remoting.RemoteClassLoader$ClassLoaderProxy.fetch3(RemoteClassLoader.java:875) > > > I moved already the anonymous class into a separate file. It did also not > work. > > Is it not possible to use the FilePath.act method in a custom pipeline > step? > > Richard > > > -- > You received this message because you are subscribed to the Google Groups > "Jenkins Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to jenkinsci-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/jenkinsci-users/2d10cb45-5d06-43d5-8c98-ed09f556eb48%40googlegroups. > com > <https://groups.google.com/d/msgid/jenkinsci-users/2d10cb45-5d06-43d5-8c98-ed09f556eb48%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS6WH%2B7AYU-egsABtMNAo621HQxqukVij0XjB2NH4y%2B9eA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.