Thanks for suggestions. I am able to build a custom build step now successfully. Final code looks like this.
JAVA File
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.FormValidation;
public class BuildStepCreator extends Builder {
private String text, text1, text2;
public String getText(){
return text;
}
public String getText1(){
return text1;
}
public String getText2(){
return text2;
}
@DataBoundConstructor
public BuildStepCreator(OptinalTextBlock enableText, OptinalTextBlock1 enableText1, OptinalTextBlock2 enableText2) {
this.text = (enableText != null) ? enableText.text : null;
this.text1 = (enableText != null) ? enableText1.text1 : null;
this.text2 = (enableText != null) ? enableText2.text2 : null;
}
public static class OptinalTextBlock {
private String text;
@DataBoundConstructor
public OptinalTextBlock(String text) {
this.text = text;
}
}
public static class OptinalTextBlock1 {
private String text1;
@DataBoundConstructor
public OptinalTextBlock1(String text1) {
this.text1 = text1;
}
}
public static class OptinalTextBlock2 {
private String text2;
@DataBoundConstructor
public OptinalTextBlock2(String text2) {
this.text2 = text2;
}
}
@Override
public boolean perform(hudson.model.AbstractBuild build, hudson.Launcher launcher, hudson.model.BuildListener listener) {
listener.getLogger().println("OptionalBlockSampleBuilder " + text);
return true;
}
@Extension
public static final class DescriptorImpl extends BuildStepDescriptor<Builder>{
/*public FormValidation doCheckTask(@QueryParameter String value){
try{
if(value.equalsIgnoreCase(null) || value.equalsIgnoreCase("")){
return FormValidation.error("Invalid Details.");
}
}catch(Exception e){
return FormValidation.error("Error validating the form details.");
}
return FormValidation.ok();
}
public FormValidation doCheckGoal(@QueryParameter String value){
try{
Integer.parseInt(value);
}catch(Exception e){
return FormValidation.error("Please provide integer in the Goal.");
}
return FormValidation.ok();
}*/
@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
// TODO Auto-generated method stub
return true;
}
@Override
public String getDisplayName() {
// TODO Auto-generated method stub
return "Job Orchectration";
}
}
}
config.jelly
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:block>
<f:optionalBlock name="enableText" title="Test Execution - PresetUp" checked="${instance.text != null}">
<f:entry title="Command" field="text">
<f:textarea />
</f:entry>
</f:optionalBlock>
</f:block>
<f:block>
<f:optionalBlock name="enableText1" title="Execute Test" checked="${instance.text1 != null}">
<f:entry title="Command" field="text1">
<f:textarea />
</f:entry>
</f:optionalBlock>
</f:block>
<f:block>
<f:optionalBlock name="enableText2" title="Post-Run Cleanup" checked="${instance.text2 != null}">
<f:entry title="Command" field="text2">
<f:textarea />
</f:entry>
</f:optionalBlock>
</f:block>
</j:jelly>