FilePath.act question

67 views
Skip to first unread message

Slide

unread,
Jul 27, 2011, 11:13:59 PM7/27/11
to jenkin...@googlegroups.com
I am currently debugging something on some additions I made to the email-ext plugin. I realized after I pushed the code to my fork, that I hadn't tested a case where the files might be on another machine correctly. So, when I went to test, I am getting the following exception, which I don't quite understand as I am new to the Java world in many respects.

ERROR: Could not send email as a part of the post-build publishers.
hudson.util.IOException2: remote file operation failed: c:\hudson\workspace\Foo at hudson.remoting.Channel@d837603:192.168.1.107
	at hudson.FilePath.act(FilePath.java:753)
	at hudson.FilePath.act(FilePath.java:739)
	at hudson.plugins.emailext.ExtendedEmailPublisher.getAttachments(ExtendedEmailPublisher.java:476)
	at hudson.plugins.emailext.ExtendedEmailPublisher.createMail(ExtendedEmailPublisher.java:305)
	at hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:249)
	at hudson.plugins.emailext.ExtendedEmailPublisher._perform(ExtendedEmailPublisher.java:241)
	at hudson.plugins.emailext.ExtendedEmailPublisher.perform(ExtendedEmailPublisher.java:203)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
	at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:644)
	at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:623)
	at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:601)
	at hudson.model.Build$RunnerImpl.cleanUp(Build.java:168)
	at hudson.model.Run.run(Run.java:1405)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
	at hudson.model.ResourceController.execute(ResourceController.java:88)
	at hudson.model.Executor.run(Executor.java:145)
Caused by: java.io.IOException: Unable to serialize hudson.FilePath$FileCallableWrapper@6e0e60c4
	at hudson.remoting.UserRequest.serialize(UserRequest.java:162)
	at hudson.remoting.UserRequest.<init>(UserRequest.java:62)
	at hudson.remoting.Channel.call(Channel.java:629)
	at hudson.FilePath.act(FilePath.java:746)
	... 15 more
Caused by: java.io.NotSerializableException: hudson.plugins.emailext.ExtendedEmailPublisher
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
	at hudson.remoting.UserRequest._serialize(UserRequest.java:151)
	at hudson.remoting.UserRequest.serialize(UserRequest.java:160)
	... 18 more

Does this mean that I need to mark ExtendedEmailPublisher as Serializable, and if so, WHY?

My code is as follows, which is inside a method in the ExtendedEmailPublisher class:

List<FilePath> files = ws.act(new FileCallable<List<FilePath>>() {
public List<FilePath> invoke(File baseDir, VirtualChannel channel)
throws IOException {
List<FilePath> results = new ArrayList<FilePath>();
FileSet src = Util.createFileSet(baseDir, attachmentsPattern);
        DirectoryScanner ds = src.getDirectoryScanner();
        for( String f : ds.getIncludedFiles() ) {
                final File file = new File(baseDir, f);
                if(file.isFile()) {
                results.add(new FilePath(file));
                } else {
                listener.getLogger().println("Skipping `" 
                + file.getName() + "' - not a file");
                }
         }                
return results;
}
private static final long serialVersionUID = 1L;
});

Can someone shed some light on my serialization woes? My plan is to then use the List<FilePath> that is returned and create attachments by reading the file (FilePath.read()). Is there a better way to achieve what I am trying to do?

Thanks,

slide
    
--
slide-o-blog
http://slide-o-blog.blogspot.com/

Bap

unread,
Jul 28, 2011, 6:09:32 AM7/28/11
to jenkin...@googlegroups.com
Hi Slide,

The issue is, your anonymous inner class that implements FileCallable
has an link to the instance of the outer class that it is defined in
(ExtendedEmailPublisger.this). One solution would be to make the
publisher Serializable, but then the entire publisher would be sent to
the remote machine and deserialized there.

A better solution would be to create a static inner class, or a top
level class that implements FileCallable, eg.

// static inner class
public static class AttachmentLister implements FileCallable {
}

Easier still would be:

FilePath[] attachments = baseDir.list(attachmentsPattern);

:-)

Bap.

Quoting Slide <slide...@gmail.com>:

> I am currently debugging something on some additions I made to the email-ext
> plugin. I realized after I pushed the code to my fork, that I hadn't tested
> a case where the files might be on another machine correctly. So, when I
> went to test, I am getting the following exception, which I don't quite
> understand as I am new to the Java world in many respects.
>
> ERROR: Could not send email as a part of the post-build
> publishers.hudson.util.IOException2

> <http://stacktrace.hudson-labs.org/search?query=hudson.util.IOException2>:


> remote file operation failed: c:\hudson\workspace\Foo at
> hudson.remoting.Channel@d837603:192.168.1.107
> at hudson.FilePath.act(FilePath.java:753)

> <http://stacktrace.hudson-labs.org/search/?query=hudson.FilePath.act&entity=method>
> at hudson.FilePath.act(FilePath.java:739)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.FilePath.act&entity=method>
> at
> hudson.plugins.emailext.ExtendedEmailPublisher.getAttachments(ExtendedEmailPublisher.java:476)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.plugins.emailext.ExtendedEmailPublisher.getAttachments&entity=method>
> at
> hudson.plugins.emailext.ExtendedEmailPublisher.createMail(ExtendedEmailPublisher.java:305)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.plugins.emailext.ExtendedEmailPublisher.createMail&entity=method>
> at
> hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:249)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.plugins.emailext.ExtendedEmailPublisher.sendMail&entity=method>
> at
> hudson.plugins.emailext.ExtendedEmailPublisher._perform(ExtendedEmailPublisher.java:241)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.plugins.emailext.ExtendedEmailPublisher._perform&entity=method>
> at
> hudson.plugins.emailext.ExtendedEmailPublisher.perform(ExtendedEmailPublisher.java:203)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.plugins.emailext.ExtendedEmailPublisher.perform&entity=method>
> at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.tasks.BuildStepMonitor$3.perform&entity=method>
> at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:644)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.model.AbstractBuild$AbstractRunner.perform&entity=method>
> at
> hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:623)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps&entity=method>
> at
> hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:601)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps&entity=method>
> at hudson.model.Build$RunnerImpl.cleanUp(Build.java:168)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.model.Build$RunnerImpl.cleanUp&entity=method>
> at hudson.model.Run.run(Run.java:1405)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.model.Run.run&entity=method>
> at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.model.FreeStyleBuild.run&entity=method>
> at hudson.model.ResourceController.execute(ResourceController.java:88)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.model.ResourceController.execute&entity=method>
> at hudson.model.Executor.run(Executor.java:145)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.model.Executor.run&entity=method>
> Caused by: java.io.IOException
> <http://stacktrace.hudson-labs.org/search?query=java.io.IOException>:


> Unable to serialize hudson.FilePath$FileCallableWrapper@6e0e60c4
> at hudson.remoting.UserRequest.serialize(UserRequest.java:162)

> <http://stacktrace.hudson-labs.org/search/?query=hudson.remoting.UserRequest.serialize&entity=method>


> at hudson.remoting.UserRequest.<init>(UserRequest.java:62)

> <http://stacktrace.hudson-labs.org/search/?query=hudson.remoting.UserRequest.%3Cinit%3E&entity=method>
> at hudson.remoting.Channel.call(Channel.java:629)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.remoting.Channel.call&entity=method>
> at hudson.FilePath.act(FilePath.java:746)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.FilePath.act&entity=method>


> ... 15 more
> Caused by: java.io.NotSerializableException

> <http://stacktrace.hudson-labs.org/search?query=java.io.NotSerializableException>:
> hudson.plugins.emailext.ExtendedEmailPublisher
> at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.writeObject0&entity=method>
> at
> java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.defaultWriteFields&entity=method>
> at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.writeSerialData&entity=method>
> at
> java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.writeOrdinaryObject&entity=method>
> at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.writeObject0&entity=method>
> at
> java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.defaultWriteFields&entity=method>
> at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1483)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.writeSerialData&entity=method>
> at
> java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1400)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.writeOrdinaryObject&entity=method>
> at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.writeObject0&entity=method>
> at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
> <http://stacktrace.hudson-labs.org/search/?query=java.io.ObjectOutputStream.writeObject&entity=method>
> at hudson.remoting.UserRequest._serialize(UserRequest.java:151)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.remoting.UserRequest._serialize&entity=method>
> at hudson.remoting.UserRequest.serialize(UserRequest.java:160)
> <http://stacktrace.hudson-labs.org/search/?query=hudson.remoting.UserRequest.serialize&entity=method>

Slide

unread,
Jul 28, 2011, 8:25:33 AM7/28/11
to jenkin...@googlegroups.com
Bap,

Thanks for the info...I feel a bit sheepish that I can just call FilePath.list...thanks :-)

slide

varun vikas

unread,
Jun 12, 2019, 5:22:19 AM6/12/19
to Jenkins Developers
@old hooky
what should be return type of

public List<String> invoke(File ws, VirtualChannel channel) function.
Here it is throwing error , attempting to use incompatible return type.

I have defined a inner class
 private static final class  AttachmentLister implements FileCallable{
@override
public List<String> invoke(File ws, VirtualChannel channel){
}
}

Note: I want to return invoke function a list, but it is giving error...how to handle it.

Robert Sandell

unread,
Jun 12, 2019, 9:32:48 AM6/12/19
to jenkin...@googlegroups.com
Probably missed the generics on FileCallable

 implements FileCallable<List<String>> {

though you should probably use MasterToSlaveFileCallable instead of the base one.

/B

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/bd7502bb-8376-45fd-86c4-87c6ebfb2747%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Robert Sandell
Software Engineer
CloudBees, Inc.
CloudBees-Logo.png
Twitter: robert_sandell

varun vikas

unread,
Jun 12, 2019, 4:06:18 PM6/12/19
to jenkin...@googlegroups.com
Thanks Robert....I have missed generics on FileCallable...it fixed the error.


Reply all
Reply to author
Forward
0 new messages