Jenkins插件构建:无法在Jenkins

时间:2017-07-30 06:44:04

标签: java jenkins jenkins-plugins

我正在尝试为Jenkins编写一个插件来将日志文件保存到MongoDB。但是我无法在Jenkins Post Build操作部分中显示此所需的配置框。 下面是我的代码。

这是我的通知程序代码:

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>

但我能在Jenkins身上看到的唯一一件事是:

enter image description here

没有配置框。我在这里错过了一些东西。

1 个答案:

答案 0 :(得分:0)

找到它。 config.jelly应该遵循与类相同的包结构。它的区分大小

How does Jenkins discover the config.jelly for a post-build plugin?