How can I share global configuration fields when writing a jenkins plugin?

I am currently writing a jenkins plugin with several collectors. I would like to share the fields in the /global.jelly descriptor with all the builders. How can I share this information? Can I use inheritance or encapsulation?

+3
source share
1 answer

A good place to start is to find the Jenkins github repository

The code you want

Jenkins.getInstance().getDescriptor( MyPluginWithGlobalConfig.class )

Which will give you the back handle you want (since there is only one instance of the handle)

Here is the one I used in a plugin (in groovy) that retrieves a handle and then calls the source file method on it

@Override
public List<String> rebuild(List<String> list){
    SeleniumDynamicCapability.DescriptorImpl sdcd = Jenkins.getInstance().getDescriptor(SeleniumDynamicCapability.class)

    List<SeleniumCapabilityRO> sc = sdcd.loadDefaultItems()

    if (sc.size() == 0)
        throw(new SeleniumException("No selenium capabilities detected"))

    setSeleniumCapabilities(sc)

    sc.each{list.add(it.toString())}
    return list;
}
+2
source

All Articles