基本上,我有与此处链接完全相同的问题: How can i send data to the logger from FileCallable back to master in a Jenkins plugin?
但我无法让它工作。我已经编写了我自己的自定义 Jenkins 插件,它必须在从服务器上运行。但是,我想记录到 master jenkins(或至少到构建日志)。这是我的代码(为简单起见删减了一点):
public class SanityTestResultsToJUnitXMLBuilder extends Builder implements Serializable {
// Some initialization code
@Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
// Define what should be run on the slave for this build
SlaveChannel slaveChannel = new SlaveChannel(sourceDirectories, destinationDirectory, listener.getLogger());
if (launcher.getChannel().call(slaveChannel).equals("NOK")){
return false;
}
return true;
}
private static final class SlaveChannel implements Callable<String, IOException>
{
// Again, some initialization code
public SlaveChannel(String sourceDirectories, String destinationDirectory, PrintStream logger){
this.sourceDirectories = sourceDirectories;
this.destinationDirectory = destinationDirectory;
this.logger = logger;
}
public String call() throws UnknownHostException
{
logger.println("Running the SanityTestResultsToJUnitXML plugin on host: " + InetAddress.getLocalHost().getHostName());
if (startProcess()){
return "OK";
} else {
return "NOK";
}
}
private boolean startProcess(){
// The code that needs to run client side
}
}
现在它在 Jenkins 中为我提供了以下输出: (这是主日志记录)
java.io.IOException: Unable to serialize nl.tba.SanityTestResultsToJUnitXML.SanityTestResultsToJUnitXMLBuilder$SlaveChannel@7e2536bb
hudson.remoting.UserRequest.serialize(UserRequest.java:166)
hudson.remoting.UserRequest.<init>(UserRequest.java:62)
hudson.remoting.Channel.call(Channel.java:721)
nl.tba.SanityTestResultsToJUnitXML.SanityTestResultsToJUnitXMLBuilder.perform(SanityTestResultsToJUnitXMLBuilder.java:61)
hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:785)
hudson.model.Build$BuildExecution.build(Build.java:199)
hudson.model.Build$BuildExecution.doRun(Build.java:160)
hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:566)
hudson.model.Run.execute(Run.java:1665)
hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
hudson.model.ResourceController.execute(ResourceController.java:88)
hudson.model.Executor.run(Executor.java:246)
Build step 'Execute SanityTestResultsToJUnitXML task' marked build as failure
Finished: FAILURE
所以基本上,记录器(它是一个 PrintStream)是不可序列化的。我如何仍然让我的奴隶登录到主要的 Jenkins ?
最佳答案
监听器对象是可序列化的。因此,您可以将此对象传递给可调用类构造函数,并在 call()
函数中使用 listener.getLogger().println();
。
关于java - Jenkins 可以在 slave 日志上自定义插件到 master 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23755290/