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