How to reload hudson configuration without rebooting?

I have a big task ahead ... changing the configuration of Hudson missions. I would like to do this from the command line. But in my experience, hudson will not reread the configuration unless you force it to "reload the configuration from disk."

I don't want to restart hudson just for a little change ... for example, do a "reboot" in apache. I don’t know how to read Java code, but I assume that what I am looking for lies in the part after saving the configuration changes.

+14
hudson
Mar 07 '11 at 6:29
source share
4 answers

Hudson / Jenkins saves the run-time configuration in memory and reloads it at startup or when you "reload the configuration from disk."

However, reloading the configuration from disk is not a reboot, just re-read the configuration.

These are all your options, reboot or reboot.

Hacking into work in different ways will be the main task, and if you still cannot read the Java code, I would not advise you to write it. Effectively, you will also need to work with the main project, so updates will not be compatible.

If you need to do all the updates using a script and then automatically reload the configuration, use hudson_cli.jar to do this.

+7
Mar 07 2018-11-11T00:
source share

Here's how to reload a job in Jenkins without rebooting or reloading the full configuration using groovy . You can also easily modify the script and reload some specific or all Jenkins jobs without reloading.

Jenkins allows you to run a script through a user interface or CLI.

UI : copy the following script to a Jenkins script page, e.g. http://www.mydomain.com/jenkins/script

 import java.io.InputStream; import java.io.FileInputStream import java.io.File; import javax.xml.transform.stream.StreamSource def hudson = hudson.model.Hudson.instance; //to get a single job //def job = hudson.model.Hudson.instance.getItem('my-job'); for(job in hudson.model.Hudson.instance.items) { if (job.name == "my-job") { def configXMLFile = job.getConfigFile(); def file = configXMLFile.getFile(); InputStream is = new FileInputStream(file); job.updateByXml(new StreamSource(is)); job.save(); } } 

CLI You can save the above script in a file and execute it remotely through the CLI as a groovy script:

  java -jar jenkins-cli.jar -s http://www.mydomain.com/jenkins groovy reload-job.groovy 

Literature:
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI (CLI) http://javadoc.jenkins-ci.org/hudson (API)

+15
Nov 19 '13 at 16:53 on
source share
 http://[jenkins-server]/reload 

Adapted from Jenkins Administration .

+8
Apr 22 '16 at 10:46 on
source share

Continuing the idea of Andreas Panagiotidis , now there is a simpler and more understandable way to reload the configuration of one Item

 import jenkins.model.Jenkins; def job_path = 'folder1/folder2/job_name' Jenkins j = Jenkins.get() def job = j.getItemByFullName(job_path) if (job) { job.doReload() } 

Note that the path may simply be 'job_name' .

0
Jan 11 '19 at 12:33
source share



All Articles