summaryrefslogtreecommitdiffstats
path: root/jenkins_jobs/config.py
diff options
context:
space:
mode:
authorDarragh Bailey <dbailey@hpe.com>2017-08-23 14:24:15 +0100
committerDarragh Bailey <dbailey@hpe.com>2017-08-23 18:31:44 +0100
commit906781a75272ae0bf986f50f6e6fcf168399f198 (patch)
treebeecc3ed4833189b4430456dddbbccb8bb43eb63 /jenkins_jobs/config.py
parent99b3cd55dc003425445437e9da97b480eaae616c (diff)
downloadpython-jenkins-job-builder-906781a75272ae0bf986f50f6e6fcf168399f198.tar.gz
python-jenkins-job-builder-906781a75272ae0bf986f50f6e6fcf168399f198.tar.xz
python-jenkins-job-builder-906781a75272ae0bf986f50f6e6fcf168399f198.zip
Migrate hipchat conf to new plugin style conf
Remove the old default hipchat configuration style in favour of using the new plugin style and provide a mechanism to copy the url value from the jenkins section automatically as part of a simple migration. This will allow removal of querying the jenkins section from existing module code and allow for better isolation. Change-Id: I6889777904ebabc01c044abcd31c9d8a20c255c4
Diffstat (limited to 'jenkins_jobs/config.py')
-rw-r--r--jenkins_jobs/config.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/jenkins_jobs/config.py b/jenkins_jobs/config.py
index cf172815..9fae91e4 100644
--- a/jenkins_jobs/config.py
+++ b/jenkins_jobs/config.py
@@ -45,10 +45,6 @@ allow_empty_variables=False
[jenkins]
url=http://localhost:8080/
query_plugins_info=True
-
-[hipchat]
-authtoken=dummy
-send-as=Jenkins
"""
CONFIG_REQUIRED_MESSAGE = ("A valid configuration file is required. "
@@ -135,9 +131,9 @@ class JJBConfig(object):
self.jenkins = defaultdict(None)
self.builder = defaultdict(None)
self.yamlparser = defaultdict(None)
- self.hipchat = defaultdict(None)
self._setup()
+ self._handle_deprecated_hipchat_config()
def _init_defaults(self):
""" Initialize default configuration values using DEFAULT_CONF
@@ -165,6 +161,37 @@ class JJBConfig(object):
return config_fp
+ def _handle_deprecated_hipchat_config(self):
+ config = self.config_parser
+
+ if config.has_section('hipchat'):
+ if config.has_section('plugin "hipchat"'):
+ logger.warning(
+ "Both [hipchat] and [plugin \"hipchat\"] sections "
+ "defined, legacy [hipchat] section will be ignored."
+ )
+ else:
+ logger.warning(
+ "[hipchat] section is deprecated and should be moved to a "
+ "[plugins \"hipchat\"] section instead as the [hipchat] "
+ "section will be ignored in the future."
+ )
+ config.add_section('plugin "hipchat"')
+ for option in config.options("hipchat"):
+ config.set('plugin "hipchat"', option,
+ config.get("hipchat", option))
+
+ config.remove_section("hipchat")
+
+ # remove need to reference jenkins section when using hipchat plugin
+ # moving to backports configparser would allow use of extended
+ # interpolation to remove the need for plugins to need information
+ # directly from the jenkins section within code and allow variables
+ # in the config file to refer instead.
+ if (config.has_section('plugin "hipchat"') and
+ not config.has_option('plugin "hipchat"', 'url')):
+ config.set('plugin "hipchat"', "url", config.get('jenkins', 'url'))
+
def _setup(self):
config = self.config_parser