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:
Thanh Ha 2016-08-19 11:14:34 -04:00
parent e47f9629bc
commit b093fee501
No known key found for this signature in database
GPG Key ID: B0CB27E00DA095AA
5 changed files with 23 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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')

View File

@ -1,4 +1,4 @@
[hipchat]
[plugin "hipchat"]
authtoken=blue
send-as=Jenkins
[jenkins]