BapHostConfiguration: is there a way to add one to system configuration?

23 views
Skip to first unread message

Ivo Bellin Salarin

unread,
Jan 30, 2015, 9:07:35 AM1/30/15
to jenkin...@googlegroups.com
Hello everybody,

Is there a way to add a BapHostConfiguration (or a CifsHostConfiguration which extends BapHostConfiguration) to the system configuration, programmatically?

This goes far beyond my knowledge regarding Jenkins internals...

Thanks in advance,
Ivo

Ivo Bellin Salarin

unread,
Jan 30, 2015, 9:36:29 AM1/30/15
to jenkin...@googlegroups.com
So far, I've wrote this code:
        CifsPublisherPluginDescriptor config = (CifsPublisherPluginDescriptor) Jenkins.getInstance().getDescriptor( CifsPublisherPlugin.class );
        boolean found = false;
        for (CifsHostConfiguration c : config.getHostConfigurations())
            found = "TEST".equals(c.getName());
        if (!found)
        {
            CifsHostConfiguration configuration = new CifsHostConfiguration("nicename", "hostname", "user", "password", "shareName", 445, 30000);
            config.getHostConfigurations().add(configuration);
        }

But then, Jenkins throws in this way:
Caused by: java.lang.UnsupportedOperationException
	at java.util.Collections$UnmodifiableCollection.add(Collections.java:1055)
	at org.jenkinsci.plugins.greenproject.GreenProject.<init>(GreenProject.java:63)
	at org.jenkinsci.plugins.greenproject.GreenProject$GreenProjectDescriptor.newInstance(GreenProject.java:96)

Ivo Bellin Salarin

unread,
Feb 5, 2015, 9:12:59 AM2/5/15
to jenkin...@googlegroups.com
I suppose that somebody will cry seeing what I've done, but I've found a way to add a configuration.

My code, right now:
        CifsPublisherPluginDescriptor config = (CifsPublisherPluginDescriptor) Jenkins.getInstance().getDescriptor( CifsPublisherPlugin.class );
        boolean found = false;
        for (CifsHostConfiguration c : config.getHostConfigurations())
            found = "TEST".equals(c.getName());
        if (!found)
        {
            CifsHostConfiguration configuration = new CifsHostConfiguration("nicename", "hostname", "user", "password", "shareName", 445, 30000);
            JSONObject formDataInner = new JSONObject();
            formDataInner.put("instance", JSONObject.fromObject(configuration));
            config.configure(req, formDataInner);
            /*config.getHostConfigurations().add(configuration);*/
        }
I've put this call in a method which receives a StaplerRequest parameter.
Reply all
Reply to author
Forward
0 new messages