|
| 1 | +/** |
| 2 | +@Author kuisathaverat |
| 3 | +@description This script allow to modified the Elasticsearch configuration from groovy. |
| 4 | +**/ |
| 5 | +import com.cloudbees.opscenter.analytics.reporter.* |
| 6 | +import com.cloudbees.opscenter.analytics.AnalyticsConfiguration |
| 7 | +import hudson.XmlFile |
| 8 | +import hudson.util.XStream2 |
| 9 | + |
| 10 | +def j = Jenkins.getInstance() |
| 11 | +def config = AnalyticsConfiguration.get() |
| 12 | + |
| 13 | +def providerES = config.getElasticsearchProvider() |
| 14 | +def provider = config.getElasticsearchLocator().getProvider(); |
| 15 | + |
| 16 | +println config.backupInterval |
| 17 | +println config.backupsEnabled |
| 18 | +println config.backupNumSnapshots |
| 19 | +println config.backupPath |
| 20 | +println config.backupName |
| 21 | + |
| 22 | +println providerES.urls |
| 23 | +println providerES.credentialsId |
| 24 | +println providerES.authScheme |
| 25 | + |
| 26 | +config.backupInterval = 300 |
| 27 | +config.backupsEnabled = true |
| 28 | +config.backupNumSnapshots = 5 |
| 29 | +config.backupPath = '/var/lib/somewhere' |
| 30 | +config.backupName = 'CloudBees-Jenkins-Analytics' |
| 31 | + |
| 32 | +providerES.urls = [new URL('http://URL_TO_ES/changed')] |
| 33 | +//read only properties |
| 34 | +//providerES.credentialsId = 'b312f53c-ce46-448f-9562-79d0b83e52f6' |
| 35 | +//providerES.authScheme = 'BASIC' |
| 36 | + |
| 37 | +config.elasticsearchProvider.ensureStopped() |
| 38 | + |
| 39 | +/** |
| 40 | +// hard way writing the XML to disk |
| 41 | +try { |
| 42 | + def configXml = new XmlFile(new File(j.getRootDir(), "operations-center-analytics-config.xml")) |
| 43 | + XStream2 xs = new XStream2() |
| 44 | + configXml.write(config) |
| 45 | +} catch (IOException e) { |
| 46 | + throw new Exception(e, "elasticsearchProvider") |
| 47 | +} |
| 48 | +**/ |
| 49 | + |
| 50 | +AnalyticsConfiguration.get().save() |
| 51 | +AnalyticsConfiguration.get().elasticsearchProvider.ensureStarted() |
0 commit comments