问题
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