Merge "Migrate hipchat conf to new plugin style conf"

This commit is contained in:
Jenkins 2017-08-24 15:19:39 +00:00 committed by Gerrit Code Review
commit 74e020052e
5 changed files with 38 additions and 6 deletions

View File

@ -47,10 +47,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. "
@ -140,9 +136,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
@ -170,6 +166,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

View File

@ -115,7 +115,7 @@ class HipChat(jenkins_jobs.modules.base.Base):
logger.fatal("The configuration file needs a hipchat section" +
" containing authtoken:\n{0}".format(e))
sys.exit(1)
self.jenkinsUrl = jjb_config.jenkins['url']
self.jenkinsUrl = jjb_config.get_plugin_config('hipchat', 'url')
self.sendAs = jjb_config.get_plugin_config('hipchat', 'send-as')
def gen_xml(self, xml_parent, data):

View File

@ -0,0 +1,3 @@
[plugin "hipchat"]
authtoken=dummy
send-as=Jenkins

View File

@ -0,0 +1 @@
hipchat004.conf

View File

@ -0,0 +1 @@
hipchat004.conf