简体   繁体   English

Jenkins自定义插件可以在奴隶日志上掌握吗?

[英]Can Jenkins custom plugin on slave log to master?

Basicaly, I have exact the same question as linked here: How can i send data to the logger from FileCallable back to master in a Jenkins plugin? 基本上,我有完全相同的问题链接在这里: 如何在Jenkins插件中将数据从FileCallable发送回主机?

but I can't get it to work. 但我无法让它发挥作用。 I have written my own custom Jenkins plugin and it has to run on a slave. 我编写了自己的自定义Jenkins插件,它必须在奴隶上运行。 I want to log, however, to the master jenkins (or at least to the build log). 但是,我想记录主jenkins(或者至少是构建日志)。 Here's my code (cut a bit for simplicity): 这是我的代码(为简单起见,有点简化):

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
    }
  }

Right now it gives me the following output in Jenkins: (And this is the master logging) 现在它在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

So basicaly, the logger (which is a PrintStream) is not serializable. 所以基本上,记录器(它是一个PrintStream)是不可序列化的。 How do I still get my slave to log to the main Jenkins? 我如何让我的奴隶登录主詹金斯?

Listener object is serializable. 监听器对象是可序列化的。 So, you can pass this object to the callable class constructor, and use listener.getLogger().println(); 因此,您可以将此对象传递给可调用类构造函数,并使用listener.getLogger().println(); in the call() function. call()函数中。

这应该打印到构建日志:

listener.getLogger().println(your_text);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从Jenkins插件登录 - Can not log from Jenkins plugin Jenkins中是否有任何插件可用于以并行方式将单元测试分发给从属计算机并将结果返回给主计算机? - Is there any plugin in Jenkins for distributing unit tests to slave machines in parallel fashion and returning back the results to the master? Jenkins CI 插件在从站上运行 - Jenkins CI Plugin run on slave Jenkins Master和Slave配置Linux到AIX - Jenkins Master and Slave configuration linux to AIX 在 jenkins 上将 Windows 7 slave 连接到 debian master 的问题 - Issue connecting windows 7 slave to debian master on jenkins 无法使用插件访问 Jenkins slave 上的文件 - Cannot access file on Jenkins slave with plugin 无法在Windows上使用主/从设备在Jenkins上运行mvn.bat - Unable to run mvn.bat on Jenkins with master/slave on Windows 需要通过jenkins slave(Windows)上的浏览器窗口上传文件,但文件位于jenkins master(linux)上 - Need to upload file through browser window on jenkins slave (Windows) but file is on jenkins master (linux) 你能为Redis集群(主/从)提供一个终点吗? - Can you have a single end point for Redis cluster(master/slave)? 我可以将MongoDB用于ActiveMQ主/从架构吗? - Can I use MongoDB for an ActiveMQ Master/Slave architecture?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM