|
If you are unfamiliar with Jelly and Jenkins' use of it, you may find it difficult to create configurable parameters for your plugin. This page describes some very simple examples to get you started. UI SamplesThe first thing you should do is install the UI Samples Plugin in your test instance so you can see how to do some common things. Loading Your First *.jellyA basic plugin structure is pom.xml Suppose you have a java class stored in src/main/java/org/myorganization/MyAction.java that you would like to define Jelly files for.
Now you can start getting more complex! Understanding the it objectAs the above section hints at, Jelly files are tied directly to classes. This means they can call methods on those classes. To reference the file they are tied to, jelly files use the it keyword. To define code, use the dollar sign and curly-braces, as so "${insert code here}". Here is a simple example:
A few things to notice: the 'get' was automatically stripped from the method name, and the first letter of the remaining method name was lower-cased. I'd recommend using the Java convention for naming methods (e.g. starting getters with 'get' and using CamelCase) so that Jelly can always find the methods. Other predefined objectsDepending on the page being rendered, other objects besides it may be predefined:
Predefined URLsPages can use the following variables to create absolute links:
(Use resURL rather than rootURL wherever possible as it permits browser caching, improving responsiveness and lessening server load.) These URLs are defined as soon as you are within an l:layout or an l:ajax block. This means that on any Jenkins page you already have them available except if your page is loaded via ajax. Then you should add the l:ajax tag. Note that until 1.505 rootURL will be empty in the typical case of Jenkins running in development mode with no context path (http://localhost:8080/); it is used for creating server-absolute paths such as /some/path for direct links. As of 1.505 it will be /jenkins in test mode, to help remind you to use it! In the rare case that you need to pass a complete URL to an external service for some reason, use app.rootUrl instead (which takes into account “Jenkins URL” from the system /configure screen). Hyperlinks in HTML has a fuller treatment of this topic. Iteratively Modifying *.jelly filesIt's worth mentioning that in most cases you don't need to re-start the Jenkins server, simply modify the *.jelly file in your editor of choice and re-request the page that will load that jelly. Objects with DescriptorsFor objects with Descriptor (such as Publisher), the general steps are as follows:
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> <f:entry title="${%Port}" field="port"> <f:textbox /> </f:entry> <f:entry title="${%Host}" field="host"> <f:textbox /> </f:entry> </j:jelly> That odd "${%...}" thing is a marker for internationalization. Help filesIf your plugin has a help-FIELD.html or help-FIELD.jelly in the src/main/resources/path/to/plugin/PluginName directory, Jenkins will put Form validationYou can write doCheckFIELD method on your descriptor to add the form validation logic. Your check method would look something like this: public FormValidation doCheckPort(@QueryParameter String value) { if(looksOk(value)) return FormValidation.ok(); else return FormValidation.error("There's a problem here"); } You can also define additional parameters with @QueryParameter to obtain values from other nearby form fields of the specified names. This is useful if your validation depends on values on the other form fields. Refer to stapler documentation for more details. Default valueIf you want the configuration page to have the initial default value, use @default. The first example shows the literal default value, while the second example shows the programmatically computed default value: <j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> <f:entry title="${%Port}" field="port"> <f:textbox default="80" /> </f:entry> <f:entry title="${%Host}" field="host"> <f:textbox default="${descriptor.defaultHost()}/> </f:entry> </j:jelly> Other jelly variablesWhen using the field= mechanism shown above you see where the data really comes from. Jenkins defines these variables which you may use as needed: descriptor and instance, which are the instance of your Descriptor class and instance of the class it describes, respectively (both are available in config.jelly, just descriptor in global.jelly). Objects without DescriptorsIf your plugin uses an object without a Descriptor, such as ComputerListener, follow these steps to include a single text box in the configuration page that will be readable within your plugin class (the one that extends Plugin).
|
Basic guide to Jelly usage in Jenkins
Skip to end of metadata
Go to start of metadata
Comments (9)
Jul 28, 2009
Mario Henrique Voorsluys says:
I'm trying to make my config.jelly or global.jelly file appear in the Global Sys...I'm trying to make my config.jelly or global.jelly file appear in the Global System Configuration from Hudson, but it never appear there. My plugin implements an TopLevelItemDescriptor. Am I doing something wrong? I mean, is it wrong to supose that an TopLevelItemDescriptor has an global.jelly file to configure it?
What I actually want is an way to set some configurations for my project type. And that every new job uses that configurations. Is it possible?
Aug 26, 2011
Hadrien Tulipe says:
Hello, This might not be the right place to post this but I could not find any ...Hello,
This might not be the right place to post this but I could not find any other. Anyway, I wonder if it is possible to do some AJAX dynamic form with jelly. I am developing a plugin that, in its configuration page, displays the user a dropdownlist. According to the value selected I need to change the content of another section of the page (a list of checkboxes actually). So basically I need to listen to onChange event or something like this. Does anyone have met the same need and found a solution?
Thanks
Aug 31, 2012
Roject Luo says:
Hi Hadrien, I am facing with the same requirement as you. Just go through the p...Hi Hadrien,
I am facing with the same requirement as you. Just go through the plugin development document. Will develop a plugin.I believe i can leverage the ui-samples plugin.
what is your final solution?
Sep 04, 2012
Hadrien Tulipe says:
Hi, it goes a while back now but I remember doing some pretty ugly stuff: I basi...Hi, it goes a while back now but I remember doing some pretty ugly stuff: I basically coded javascript inside my jelly template. I don't think there is another way around but I would like to be proven wrong.
Overall, I don't really see why jenkins is using jelly for front-end pages where such great frameworks are now available.
Oct 15, 2012
Roject Luo says:
Finally developed a dynamic-parameter plugin to solve my issue. This plug...Finally developed a dynamic-parameter plugin to solve my issue.
This plugin can read a file to create choice parameters dynamically. and further more, it can generate the options value at runtime:
Nov 16, 2012
Ramesh Pasham says:
Hi Roject Luo, I have also same requirement on dynamic parameter plugin but som...Hi Roject Luo,
I have also same requirement on dynamic parameter plugin but some what different. Based on the other parameter it should read and generate choise parameters dynamically at runtime itself. Can you help on this one?
Nov 18, 2012
Roject Luo says:
I developed a configurable dynamical parameter plugin. It will generate choice p...I developed a configurable dynamical parameter plugin. It will generate choice parameter at runtime. Just trying to publish this to jenkins.
same of conifg for parameters:
<parameter name="Jenkins" value=""> <!
- script depends on environment and application -> <!- script depends on application only -> <parameter name="Application" value="APP1"> <parameter name="Environment" value="ASM" /> <parameter name="Environment" value="SYS" /> <parameter name="Environment" value="PROD" /> </parameter> <parameter name="Application" value="APP2"> <parameter name="Environment" value="PROD" /> </parameter></parameter>
<parameter name="Jenkins" value="">
<!
- script depends on application only -><parameter name="Application" value="APP1">
<parameter name="Environment" value="ASM" />
<parameter name="Environment" value="SYS" />
<parameter name="Environment" value="PROD" />
</parameter>
<parameter name="Application" value="APP2">
<parameter name="Environment" value="PROD" />
</parameter>
</parameter>
Mar 03, 2014
Lorelei McCollum says:
Hi - I am trying to understand the difference between objects with descriptors v...Hi - I am trying to understand the difference between objects with descriptors vs ones without them.. is there any more documentation on this I could read. I am new to plugin development and just learning.
Thanks!
Jul 12, 2014
irfan sayed says:
hi, i am new to plugin development i have written one new plugin but it ...hi,
i am new to plugin development
i have written one new plugin but it is not working as expected
can someone please review my code
regards
Add Comment