2017-07-30 183 views
1

我想为Jenkins编写一个插件来将日志文件保存到MongoDB。但是我不能在Jenkins Post Build操作部分显示这个所需的配置框。 下面是我的代码。Jenkins插件版本:在Jenkins上看不到所需的配置

这是我的通知代码:

public class SaveLogsPublisher extends Notifier { 

    private final String hostName; 
    private final String port; 
    private final boolean saveToMongoDB; 
    private final String logFilePath; 

    // Fields in config.jelly must match the parameter names in the "DataBoundConstructor" 
    @DataBoundConstructor 
    public SaveLogsPublisher(String hostName, String port, boolean saveToMongoDB, String logFilePath) { 
     this.hostName = hostName; 
     this.port = port; 
     this.saveToMongoDB = saveToMongoDB; 
     this.logFilePath = logFilePath; 
    } 

    public BuildStepMonitor getRequiredMonitorService() { 
     return BuildStepMonitor.BUILD; 
    } 

    /** 
    * We'll use this from the <tt>config.jelly</tt>. 
    */ 
    public String getHostName() { 
     return hostName; 
    } 

    public String getPort() { 
     return port; 
    } 

    public boolean getSaveToMongoDB() { 
     return saveToMongoDB; 
    } 

    public String getLogFilePath() { 
     return logFilePath; 
    } 

    /** 
    * Save to Mongo DB 
    */ 
    @Override 
    public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) { 
     return true; 
    } 


    // Overridden for better type safety. 
    // If your plugin doesn't really define any property on Descriptor, 
    // you don't have to do this. 
    @Override 
    public DescriptorImpl getDescriptor() { 
     return (DescriptorImpl) super.getDescriptor(); 
    } 

    /** 
    * Descriptor for {@link SaveLogsPublisher}. Used as a singleton. 
    * The class is marked as public so that it can be accessed from views. 
    * <p> 
    * <p> 
    * See 
    * for the actual HTML fragment for the configuration screen. 
    */ 
    @Extension // This indicates to Jenkins that this is an implementation of an extension point. 
    public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> { 
     /** 
     * This human readable name is used in the configuration screen. 
     */ 
     public String getDisplayName() { 
      return "Save to Mongo DB"; 
     } 

     public boolean isApplicable(Class<? extends AbstractProject> aClass) { 
      // Indicates that this builder can be used with all kinds of project types 
      return true; 
     } 

    } 

} 

而且我Config.jelly

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> 
    <!-- 
    This jelly script is used for per-project configuration. 
    See global.jelly for a general discussion about jelly script. 
    --> 
    <f:entry title="Save to Mongo DB" field="saveToMongoDB" description="Check if we should save the logs to Database."> 
    <f:checkbox /> 
    </f:entry> 

    <f:entry title="Mongo DB host" field="hostName" description="Host name of the Mongo DB server"> 
     <f:textbox /> 
    </f:entry> 

    <f:entry title="Mongo DB Port" field="port" description="Port Number of the MongoDB to be connected"> 
    <f:textbox /> 
    </f:entry> 

    <f:entry title="Path of Log file" field="logFilePath" description="Full folder path of the jenkins log to be read"> 
     <f:textbox /> 
    </f:entry> 

</j:jelly> 

但我可以在我的詹金斯唯一看到的是这样的:

enter image description here

没有配置框。我在这里错过了什么。

+0

找到了。 config.jelly应该和类一样遵循相同的包结构。和** **区分大小写**。 https://stackoverflow.com/questions/29424226/how-does-jenkins-discover-the-config-jelly-for-a-post-build-plugin – Nagendra555

回答