Reputation: 732
I want to script my Jenkins installation. I use always use the "stable" release of Jenkins (currently : 2.121.3), but I noticed that when I install the stable release, the update website (in admin > plugin > advance) is setted to "https://updates.jenkins.io/update-center.json" which is not the stable release. I have to change this setting to "http://updates.jenkins-ci.org/stable/update-center.json".
I want to do it automatically, by script. I know I can change this setting in the /var/lib/jenkins/hudson.model.UpdateCenter.xml
file, but I prefere to use a Groovy script to do this.
But I cant find a way to change this settings in Groovy scriptbecause i'm not aware of the Jenkins/Hudson data model neither the Groovy syntax, I dont know how to change and save the setting.
Upvotes: 1
Views: 1307
Reputation: 1050
I was also searching for something like this, I just solved this using groovy, hope this helps anyone else as well.
import hudson.model.UpdateCenter;
import hudson.model.UpdateSite;
import hudson.util.PersistedList;
import jenkins.model.Jenkins
site = "http://updates.jenkins.io/update-center.json"; // TBD: update as necessary
PersistedList < UpdateSite > sites = Jenkins.getInstance().getUpdateCenter().getSites();
for (UpdateSite s: sites) {
if (s.getId().equals(UpdateCenter.ID_DEFAULT))
sites.remove(s);
}
sites.add(new UpdateSite(UpdateCenter.ID_DEFAULT, site));
Upvotes: 2
Reputation: 6790
As for the current Jenkins core API version (>2.16X),
The UpdateCenter Javadoc and UpdateSite Javadoc do not display any method that allows to either add or update the update site.
The UpdateCenter Class source code confirms that the values of the update sites are actually loaded (I suppose at the start of Jenkins) with no possibility to alter the lists afterwards.
So I guess the only way to set a custom update site is to have a custom update site is to feed Jenkins with a custom hudson.model.UpdateCenter.xml
at the start.
Here're a couple of observations that I made (please confirm or invalidate in the comments below, as I'm not 100% sure about these):
default
Upvotes: 1