Add convenience function for plugin namespace
Plugins can use get_plugin_config() which will search in a plugin namespace. For example: [plugin "hipchat"] authtoken = 123token - Updated hipchat plugin to use get_plugin_config() - Updated stash plugin to use get_plugin_config() - Backwards compatibility is kept by falling back to the old configuration setting if the new one is not found. - Warning is displayed if the old configuration method is used. Change-Id: I7cff063e2d179a5d9a3f221c85de6864382bc477 Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
parent
e47f9629bc
commit
b093fee501
@ -14,9 +14,9 @@ query_plugins_info=False
|
||||
##### This is deprecated, use job_builder section instead
|
||||
#ignore_cache=True
|
||||
|
||||
[hipchat]
|
||||
[plugin "hipchat"]
|
||||
authtoken=dummy
|
||||
|
||||
[stash]
|
||||
[plugin "stash"]
|
||||
username=user
|
||||
password=pass
|
||||
password=pass
|
||||
|
@ -310,3 +310,18 @@ class JJBConfig(object):
|
||||
" the " + section + " section, blank default" +
|
||||
" value will be applied:\n{0}".format(e))
|
||||
return result
|
||||
|
||||
def get_plugin_config(self, plugin, key):
|
||||
value = self.get_module_config('plugin "{}"'.format(plugin), key)
|
||||
|
||||
# Backwards compatibility for users who have not switched to the new
|
||||
# plugin configuration format in their config. This code should be
|
||||
# removed in future versions of JJB after 2.0.
|
||||
if not value:
|
||||
value = self.get_module_config(plugin, key)
|
||||
logger.warning(
|
||||
"Defining plugin configuration using [" + plugin + "] is"
|
||||
" deprecated. The recommended way to define plugins now is by"
|
||||
" configuring [plugin \"" + plugin + "\"]")
|
||||
|
||||
return value
|
||||
|
@ -250,7 +250,7 @@ def findbugs_settings(xml_parent, data):
|
||||
def get_value_from_yaml_or_config_file(key, section, data, jjb_config):
|
||||
result = data.get(key, '')
|
||||
if result == '':
|
||||
result = jjb_config.get_module_config(section, key)
|
||||
result = jjb_config.get_plugin_config(section, key)
|
||||
return result
|
||||
|
||||
|
||||
|
@ -101,9 +101,9 @@ class HipChat(jenkins_jobs.modules.base.Base):
|
||||
unless actually required.
|
||||
"""
|
||||
jjb_config = self.registry.jjb_config
|
||||
if(not self.authToken):
|
||||
if not self.authToken:
|
||||
try:
|
||||
self.authToken = jjb_config.get_module_config('hipchat',
|
||||
self.authToken = jjb_config.get_plugin_config('hipchat',
|
||||
'authtoken')
|
||||
# Require that the authtoken is non-null
|
||||
if self.authToken == '':
|
||||
@ -115,7 +115,7 @@ class HipChat(jenkins_jobs.modules.base.Base):
|
||||
" containing authtoken:\n{0}".format(e))
|
||||
sys.exit(1)
|
||||
self.jenkinsUrl = jjb_config.jenkins['url']
|
||||
self.sendAs = jjb_config.get_module_config('hipchat', 'send-as')
|
||||
self.sendAs = jjb_config.get_plugin_config('hipchat', 'send-as')
|
||||
|
||||
def gen_xml(self, xml_parent, data):
|
||||
hipchat = data.get('hipchat')
|
||||
|
@ -1,4 +1,4 @@
|
||||
[hipchat]
|
||||
[plugin "hipchat"]
|
||||
authtoken=blue
|
||||
send-as=Jenkins
|
||||
[jenkins]
|
||||
|
Loading…
Reference in New Issue
Block a user