Problem with FilePath.act() in custom pipeline step

61 views
Skip to first unread message

Richard Hierlmeier

unread,
Feb 27, 2018, 3:38:21 AM2/27/18
to Jenkins Users

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


Baptiste Mathus

unread,
Mar 4, 2018, 8:20:01 AM3/4/18
to jenkins...@googlegroups.com
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.

--
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+unsubscribe@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.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages