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
etc
jenkins_jobs
tests/hipchat/fixtures
@ -14,9 +14,9 @@ query_plugins_info=False
|
|||||||
##### This is deprecated, use job_builder section instead
|
##### This is deprecated, use job_builder section instead
|
||||||
#ignore_cache=True
|
#ignore_cache=True
|
||||||
|
|
||||||
[hipchat]
|
[plugin "hipchat"]
|
||||||
authtoken=dummy
|
authtoken=dummy
|
||||||
|
|
||||||
[stash]
|
[plugin "stash"]
|
||||||
username=user
|
username=user
|
||||||
password=pass
|
password=pass
|
@ -310,3 +310,18 @@ class JJBConfig(object):
|
|||||||
" the " + section + " section, blank default" +
|
" the " + section + " section, blank default" +
|
||||||
" value will be applied:\n{0}".format(e))
|
" value will be applied:\n{0}".format(e))
|
||||||
return result
|
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):
|
def get_value_from_yaml_or_config_file(key, section, data, jjb_config):
|
||||||
result = data.get(key, '')
|
result = data.get(key, '')
|
||||||
if result == '':
|
if result == '':
|
||||||
result = jjb_config.get_module_config(section, key)
|
result = jjb_config.get_plugin_config(section, key)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,9 +101,9 @@ class HipChat(jenkins_jobs.modules.base.Base):
|
|||||||
unless actually required.
|
unless actually required.
|
||||||
"""
|
"""
|
||||||
jjb_config = self.registry.jjb_config
|
jjb_config = self.registry.jjb_config
|
||||||
if(not self.authToken):
|
if not self.authToken:
|
||||||
try:
|
try:
|
||||||
self.authToken = jjb_config.get_module_config('hipchat',
|
self.authToken = jjb_config.get_plugin_config('hipchat',
|
||||||
'authtoken')
|
'authtoken')
|
||||||
# Require that the authtoken is non-null
|
# Require that the authtoken is non-null
|
||||||
if self.authToken == '':
|
if self.authToken == '':
|
||||||
@ -115,7 +115,7 @@ class HipChat(jenkins_jobs.modules.base.Base):
|
|||||||
" containing authtoken:\n{0}".format(e))
|
" containing authtoken:\n{0}".format(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
self.jenkinsUrl = jjb_config.jenkins['url']
|
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):
|
def gen_xml(self, xml_parent, data):
|
||||||
hipchat = data.get('hipchat')
|
hipchat = data.get('hipchat')
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[hipchat]
|
[plugin "hipchat"]
|
||||||
authtoken=blue
|
authtoken=blue
|
||||||
send-as=Jenkins
|
send-as=Jenkins
|
||||||
[jenkins]
|
[jenkins]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user