简体   繁体   中英

Form Validation in Jenkins Plugin Development

I am trying to get form validation for my Jenkins plugin.

This is my plugin java source. it's a SimpleBuildStep where someone must put in an ID in my form. I'm just trying to get it to work. When I empty out the field, nothing happens.

public class WATSBuilder extends hudson.tasks.Builder implements SimpleBuildStep {

    private String suvId;
    private String suvPassword;




   @Extension
   public static class Descriptor extends BuildStepDescriptor<hudson.tasks.Builder> {

     @Override
            public boolean isApplicable(Class<? extends AbstractProject> jobType) {
                return FreeStyleProject.class.isAssignableFrom(jobType);
            }

      @Override
      public String getDisplayName(){
            return "Jetson WATS Plugin";
      }

     public FormValidation doChecksuvId(@QueryParameter String value, @AncestorInPath AbstractProject project) {
      if( value.isEmpty() ){
          return FormValidation.error("There's a problem here");
        } else {
          return FormValidation.ok();
        }


         }
.
.
.
}

This is my jelly config:

<f:section title="Environment">
    <f:radioBlock title="SUV" value="suv" checked="${instance.isSUVEnv('suv')}" name="env" inline="true">
        <f:entry title="SUV ID" field="suvId" >
            <f:textbox default="i-xxxxxxxxxxxx" />
            <!-- checkUrl="'${rootURL}/plugin/jetson/checkSuvid?val='+this.value" -->
        </f:entry>
    </f:radioBlock>
    <f:radioBlock title="Other" value="other" checked="${instance.isSUVEnv('other')}" name="env" inline="true">
        <f:entry title="Endpoint" field="watsEndpoint">
            <f:textbox/>
        </f:entry>
    </f:radioBlock>
</f:section>

您需要使用大写的字段名称,所以请使用doCheckSuvId而不是doChecksuvId

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM