Jenkins:config.jelly中的validateButton用于没有描述符的类 [英] Jenkins: validateButton in config.jelly for a class without Descriptor

查看:208
本文介绍了Jenkins:config.jelly中的validateButton用于没有描述符的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Plugin类,没有Descriptor:

@Extension
public class Plugin extends hudson.Plugin {

    // ...

    public FormValidation doValidateForm(String s) {
        return FormValidation.ok("Hello world! Your 's': " + s);
    }
}

我为此课有一个config.jelly:

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
    <!-- ... -->
                    <f:entry title="Test">
                        <f:textbox name="test" value="123" field="test"/>
                    </f:entry>
                    <f:validateButton title="Test" progress="Testing..."
                                      method="validateForm" with="test"/>
    <!-- ... -->
</j:jelly>

问题是当我按下按钮时,我无法让Jenkins向我的方法发送请求.不管我在validateButtonmethod属性中写什么,即使我写了类似http://localhost:8080/的内容,Jenkins都将其放在/descriptorByName/jenkins.model.GlobalPluginConfiguration/之后.如何连接doValidateForm方法和validateButton?

The problem is I can't make Jenkins send request to my method when I press the button. No matter what I write in method attribute of validateButton, Jenkins just puts it after /descriptorByName/jenkins.model.GlobalPluginConfiguration/, even if I write something like http://localhost:8080/. How can I connect my doValidateForm method and my validateButton?

推荐答案

必须在描述符上才能获取免费功能.

This has to be on the descriptor to get the free functionality.

您还需要这样注释您的参数

You also need to annotate your parameters like this

FormValidation doCheckServer(@QueryParameter String test) {
    //stuff
}

添加描述符是一个简单更改

class Plugin extends AbstractDescribableImpl<Plugin> {
    String test;

    @DataBoundConstructor
    public Plugin(String test) {
        this.test = test; 
    }

    ....

    @Extension
    public static class DescriptorImpl extends Descriptor<Plugin> {
        public String getDisplayName() { return ""; }

        public FormValidation doValidateForm(@QueryParameter String test) {
            return FormValidation.ok("Hello world! Your 'test': " + test);
          }
    }
}

未经测试,您需要做更多工作才能从工作中的XML反序列化

Not tested and you will need to do more work to deserialize it from the XML in the job

这篇关于Jenkins:config.jelly中的validateButton用于没有描述符的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆