Jenkins: validateButton in config.jelly for a class without Descriptor

落花浮王杯 提交于 2019-12-12 03:24:17

问题


I have the Plugin class without Descriptor:

@Extension
public class Plugin extends hudson.Plugin {

    // ...

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

And I have a config.jelly for this class:

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

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?


回答1:


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
}

Adding a descriptor is a simple change

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

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



来源:https://stackoverflow.com/questions/35724841/jenkins-validatebutton-in-config-jelly-for-a-class-without-descriptor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!