Reload Job config.xml programmatically

3,653 views
Skip to first unread message

mpapo - Michaël Pailloncy

unread,
Jul 26, 2012, 8:35:01 AM7/26/12
to jenkin...@googlegroups.com
Hi,

I would like to reload config.xml file of a job programmatically.
I've tried :
AbstractItem item = (AbstractItem) Jenkins.getInstance().getItem("myjob");
File directoryConfigXml = item.getConfigFile().getFile().getParentFile();
Items.load(item.getParent(), directoryConfigXml);

But this code portion does not reload configuration and the jobs still has its old configuration in cache.

If I reload Jenkins, the configuration is correctly reloaded.

How can I reload the configuration of my job?


Michaël Pailloncy

unread,
Jul 27, 2012, 2:52:34 AM7/27/12
to jenkin...@googlegroups.com
I've tried :
AbstractItem item = (AbstractItem) Jenkins.getInstance().getItem("myjob");
File directoryConfigXml = item.getConfigFile().getFile().getParentFile();
Item updatedItem = Items.load(item.getParent(), directoryConfigXml);
Jenkins.getInstance().putItem((TopLevelItem)updatedItem);

It works, but it delete and re-create the job.
Nobody knows a more simple way to just reload the job configuration from disk (without having to reload all Jenkins configurations) ?

Thank you in advance for any help.

2012/7/26 mpapo - Michaël Pailloncy <mpap...@gmail.com>

Frederik Fromm

unread,
Jul 27, 2012, 3:51:11 AM7/27/12
to jenkin...@googlegroups.com
My best try to update jobs' config was using a groovy script with the groovy plugin. Create a job object from an xml file using XStream.fromXml and then create or get a job from your jenkins instance, store the values of the loaded properties into the second job instance and do job.save(). That should work.
 
This way I have patched lots of jobs where the config slicing plugin could not help.
 
Regard, Frederik

2012/7/27 Michaël Pailloncy <mpap...@gmail.com>

Michaël Pailloncy

unread,
Jul 27, 2012, 4:16:30 AM7/27/12
to jenkin...@googlegroups.com
Thanks a lot !
I just watched the configuration slicing plugin thinking it might help me. But like your solution, it needs to knows which properties to modify.
I'm in a case that I know that the config.xml file has been modified, but I don't anything about what was modified.

Any other suggestion ?


2012/7/27 Frederik Fromm <frederi...@gmail.com>

Stephen Connolly

unread,
Jul 27, 2012, 4:42:45 AM7/27/12
to jenkin...@googlegroups.com
load the xml from disk and POST it to jenkins_url/jobs/___/config.xml 

Michaël Pailloncy

unread,
Jul 27, 2012, 5:12:32 AM7/27/12
to jenkin...@googlegroups.com
I'm developing a plugin, so I'm server side and have access to all Jenkins objects. It is really necessary to do it like that?

2012/7/27 Stephen Connolly <stephen.al...@gmail.com>

Stephen Connolly

unread,
Jul 27, 2012, 5:37:34 AM7/27/12
to jenkin...@googlegroups.com
nope but you could make the equivalent call to the do___ method

Michaël Pailloncy

unread,
Jul 27, 2012, 5:43:46 AM7/27/12
to jenkin...@googlegroups.com
Ok ! thank you very much, I'll study this solution.

2012/7/27 Stephen Connolly <stephen.al...@gmail.com>
Reply all
Reply to author
Forward
0 new messages