Maintaining such support is preferred where it is easily possible, to allow plugins to be updated and used
on Jenkins deployments with older core versions (including current LTS 2.263.x at the time of this writing).
There is a jelly property set on Jenkins controllers that use div’s for form layout called divBasedFormLayout
,
so you can adapt your plugin UI based on the presence of this property.
Note: This property is only set if the form tag uses the f:form
jelly tag, and not the HTML form
tag,
this will be done automatically for you in form sections but not in actions or custom views.
<j:jelly xmlns:j="jelly:core" xmlns:d="jelly:define" xmlns:local="local">
<d:taglib uri="local">
<d:tag name="blockWrapper">
<j:choose>
<j:when test="${divBasedFormLayout}">
<div>
<d:invokeBody/>
</div>
</j:when>
<j:otherwise>
<table style="width:100%">
<d:invokeBody/>
</table>
</j:otherwise>
</j:choose>
</d:tag>
</d:taglib>
<local:blockWrapper>
...
</local:blockWrapper>
</j:jelly>
This will use a table on Jenkins controllers that don’t have divBasedFormLayout
and will use a div when it is set.
Note: You will likely need more tags to adapt the tr
and td
tags to divs see multiple-scms-plugin#25 for a full example, or notification-plugin#40 for an even more extensive example of different wrapper types (note they are shipped in separate files, included from the jelly files to edit with references like xmlns:p="/lib/notification"
with a path part relative to src/main/resources/
directory).
blockWrapper {
p('Hello, World!')
}
def blockWrapper(Closure closure) {
if (context.getVariableWithDefaultValue("divBasedFormLayout", false) == true) {
div() {
closure.call()
}
} else {
table(style: "width: 100%") {
closure.call()
}
}
}