Writing to main-config.xml using MainConfigProcessor
Hi,
I am trying to store some data across server restarts and have tried implementing MainConfigProcessor. I have added some code to the writeTo method but I cannot figure out how to get TeamCity to call this (aside from e.g. changing global server settings in the UI and pressing the save button)
Would anyone be able to give me some advise please?
Many thanks,
Chris
Please sign in to leave a comment.
Sorry for delay.
Is it correct that you are writing a plugin which should provide some user interface for some global settings, and you want these settings to be stored in main-config.xml? Right now it could be easier and safer to store them in some other file under .BuildServer/config. For the editing part, you could plug your page into the Administration page navigation (left navigation sidebar). For this your extension should extend AdminPage base class which is available since 7.0.
Essentially we wanted to add a global setting for our extension and figured the MainConfigProcessor interface was there specifically for doing this with main-config.xml - I don't really want to reinvent the wheel if this could be made to work, so at the moment we are doing this
jQuery.post('/admin/serverConfigGeneral.html');
in order to cause the server to save to the file with the updated settings, but it would obviously be far cleaner if there was a way for us to do this from Java.
Thanks,
Chris
Hi, I'm writing to you from the future. Just curious if you ever found a better way than using jQuery to trigger the config file save (which does still work, btw-- great hack!)
Regards,
~John
Hi John,
Unfortunately I only worked on that project for a month or so after this thread was made, and therefore do not know if my successors ever found a way of doing this without the hack - sorry I couldn't be of more use to you :(
All the best,
Chris
Hi Pavel,
I've got basically the same question as Chris had: I want to store some configuration for my plugin. I first implemented the MainConfigProcessor, but found like Chris the only way to trigger that code to write main-config.xml was a POST to /admin/serverConfigGeneral.html --and at least on the TeamCity installation I'm testing on, that overwrote the file and ended up destroying some data that team-city needed on its next boot (the "version" key, I think). So scrap that approach.
As you mentioned, it is "easier and safer to store them in some other file under .BuildServer/config", rather than main-config.xml, but I can't figure out a way to get the value of TEAMCITY_DATA_PATH in order to write out my config file. Is there a descriptor class somewhere that I can query for the value? Right now the closest thing I've found to this is the PluginDescriptor.getPluginRoot() method, but that returns "~/.BuildServer/plugins/.unpacked/my-plugin", and that is not where I want to store config files either!
Is the best way to take that plugin root and replace plugins/... with config/ ?
Thanks,
~John
Came across jetbrains.buildServer.serverSide.ServerPaths right after posting this yesterday. Does the job perfectly: http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/ServerPaths.html#getConfigDir()