【问题标题】:Jelly validateButton can't access Java methodJelly validateButton 无法访问 Java 方法
【发布时间】:2015-05-26 14:04:00
【问题描述】:

我正在尝试编写一个简单的 Jenkins 插件。 但是,我遇到了 Jelly validateButton 的问题;它无法访问 Java 方法。

由于我对 Jelly 和 Java 不太熟悉,所以我一直使用这个 Wiki 作为参考点 - https://wiki.jenkins-ci.org/display/JENKINS/Jelly+form+controls

这是我在 Jenkins 中得到的:

ERROR
HTTP ERROR 404

Problem accessing /tagBuild. Reason:

    Not Found

Powered by Jetty://

这是我的果冻代码:

<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler" xmlns:f="lib/form" xmlns:t="/lib/hudson">
    <l:layout norefresh="true">
        <st:include page="sidepanel.jelly" it="${it.build}"/>
        <l:main-panel>
            <f:form method="post">
                <f:entry title="${%Milestone Name}" help="Enter Milestone name to tag with...">
                    <f:textbox field="milestoneName" />
                </f:entry>
                <f:validateButton title="${%Tag Build}" progress="${%Tagging...}" method="tagBuild" with="milestoneName" />
            </f:form>
        </l:main-panel>
    </l:layout>
</j:jelly>

这里是 Java 类:

import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.util.FormValidation;
import org.kohsuke.stapler.QueryParameter;

public class MilestoneLabelingPlugin implements Action {
    AbstractBuild build;
    public AbstractBuild getBuild() { return this.build; }
    public MilestoneLabelingPlugin(AbstractBuild build) {
        super();
        this.build = build;
    }
    public String getUrlName() { return "MilestoneLabelingPlugin"; }
    public String getDisplayName() { return "Label Milestone Build"; }
    public String getIconFileName() { return "/plugin/milestone-labeling-plugin/icon/labelMilestoneBuild.png"; }

    public FormValidation doTagBuild(@QueryParameter("milestoneName") final String milestoneName) {
        return FormValidation.ok("Success!!" + milestoneName);
    }

}

最有趣的部分是我尝试使用提交按钮,并配置为运行一个方法并且它有效。唯一的问题是我无法从输入字段中读取值:/

有人遇到过类似问题吗?或者谁能​​告诉我我做错了什么。

提前感谢所有回复。

【问题讨论】:

    标签: java jenkins continuous-integration jenkins-plugins jelly


    【解决方案1】:

    我认为这个问题在Wiki 中解释过:“这个方法需要在拥有这个表单片段的描述符类上。”看起来只有 Describable 类支持 FormValidation 方法。

    【讨论】:

    • 嗨,我有点困惑。根据这个 wiki (github.com/jenkinsci/pretested-integration-plugin/wiki/…),描述符类是您实现 getDisplayName() 方法的类。此外,大多数描述 Java 和 Jelly 之间交互的 Wiki 都说,Jelly 会根据包含特定 .jelly 文件的包名称找到正确的 Java 类以调用方法。
    • 没错,但有些类实现了 Describable 接口,将其元数据存储在 Descriptor 对象中,如 Descriptor 类文档中所述:javadoc.jenkins-ci.org/?hudson/model/Descriptor.html。动作是不可描述的,所以看起来你不能把 FormValidation 放在它们上面。稍后我会验证这一点,现在没有时间。
    • 嗨,你能建议我应该实现哪个接口吗?问题是,我需要我的插件仅在构建级别可用(在单击特定构建之后)。为此,我发现我唯一可以使用的 ExtensionPoint 是 TransientActionFactory。似乎需要实施 Action...所以我有点卡住...也许您知道我可以使用的其他 ExtensionPoint...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多