When updating a plugin to support pipeline script, how do I handle an optionalBlock section?
I've been using https://github.com/jenkinsci/pipeline-plugin/blob/master/DEVGUIDE.md#user-content-build-wrappers-1 as a guide to updating my plugins to support pipeline script and that went well until I tried up update a plugin that uses an optionalBlock.
Using the pipeline syntax generator I get an exception that it is expecting a boolean for the optional block parameter and if I make it a boolean it complains about needing to pass a JSonObject!!!
<f:optionalBlock title="Wait Till Build Completed" field="waitTillBuildCompleted" >
<f:entry title="Show BuildMaster Log on Failure" field="printLogOnFailure" >
<f:checkbox default="false" />
</f:entry>
</f:optionalBlock>
public DeployToStageBuilder(String toStage, JSONObject waitTillBuildCompleted) {
this.toStage = toStage;
if (waitTillBuildCompleted != null) {
this.waitTillBuildCompleted = true;
this.printLogOnFailure = "true".equalsIgnoreCase(waitTillBuildCompleted.getString("printLogOnFailure"));
} else {
this.waitTillBuildCompleted = false;
this.printLogOnFailure = false;
}
}
Maybe I'm not looking in the right places or I just don't understand the code but I cannot see how to get an optionalProperty to work. The only example I can find this the ui-samples-plugin which has an overly complicated example that I cannot follow.
or
<f:optionalBlock
title="Set Build Variables in BuildMaster" field="setBuildVariables"
>
<f:entry title="Copy Previous Build's
Variables" field="preserveVariables" >
<f:checkbox
default="false" />
</f:entry>
<f:entry title="Variables"
field="variables" >
<f:expandableTextbox />
</f:entry>
</f:optionalBlock>
Class Snippet
@DataBoundSetter
public final void setSetBuildVariables(SetBuildVariables
setBuildVariables) {
if (setBuildVariables != null) {
this.setBuildVariables = true;
this.preserveVariables = setBuildVariables.preserveVariables;
this.variables =
setBuildVariables.variables;
} else {
this.setBuildVariables = false;
this.preserveVariables = false;
this.variables = null;
}
}
public static final class SetBuildVariables {
private final boolean preserveVariables;
private final String variables;
@DataBoundConstructor
public SetBuildVariables(boolean preserveVariables, String
variables) {
this.preserveVariables =
preserveVariables;
this.variables = variables;
}
}
Thanks in advance
Andrew
public class WaitTillCompleted extends AbstractDescribableImpl<WaitTillCompleted> {
private final boolean printLogOnFailure;public boolean isPrintLogOnFailure() {
return printLogOnFailure;
}@DataBoundConstructor
public WaitTillCompleted(boolean printLogOnFailure) {
this.printLogOnFailure = printLogOnFailure;
}
@Extension
public static class DescriptorImpl extends Descriptor<WaitTillCompleted> {
@Override
public String getDisplayName() {
return "";
}
}
}
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="Show BuildMaster Log on Failure" field="printLogOnFailure" >
<f:checkbox default="false" />
</f:entry>
</j:jelly>
--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/86581742-e4dd-4e26-943b-62ba8bd4b7dc%40googlegroups.com.