summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanh Ha <thanh.ha@linuxfoundation.org>2016-08-19 11:14:34 -0400
committerThanh Ha <thanh.ha@linuxfoundation.org>2016-11-11 13:34:16 -0500
commitb093fee5017ca4b71b0856ce88f4e9f3d28f7e3d (patch)
tree3825a68d4e0007d1ec6e7a20cde542c713120309
parente47f9629bc7483d597602c468619c914c421f8e3 (diff)
downloadpython-jenkins-job-builder-b093fee5017ca4b71b0856ce88f4e9f3d28f7e3d.tar.gz
python-jenkins-job-builder-b093fee5017ca4b71b0856ce88f4e9f3d28f7e3d.tar.xz
python-jenkins-job-builder-b093fee5017ca4b71b0856ce88f4e9f3d28f7e3d.zip
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>
-rw-r--r--etc/jenkins_jobs.ini-sample6
-rw-r--r--jenkins_jobs/config.py15
-rw-r--r--jenkins_jobs/modules/helpers.py2
-rw-r--r--jenkins_jobs/modules/hipchat_notif.py6
-rw-r--r--tests/hipchat/fixtures/hipchat003.conf2
5 files changed, 23 insertions, 8 deletions
diff --git a/etc/jenkins_jobs.ini-sample b/etc/jenkins_jobs.ini-sample
index 55515e23..5fd655f5 100644
--- a/etc/jenkins_jobs.ini-sample
+++ b/etc/jenkins_jobs.ini-sample
@@ -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 \ No newline at end of file
+password=pass
diff --git a/jenkins_jobs/config.py b/jenkins_jobs/config.py
index a22c48af..19d13b82 100644
--- a/jenkins_jobs/config.py
+++ b/jenkins_jobs/config.py
@@ -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
diff --git a/jenkins_jobs/modules/helpers.py b/jenkins_jobs/modules/helpers.py
index ff824555..bf0bb9f4 100644
--- a/jenkins_jobs/modules/helpers.py
+++ b/jenkins_jobs/modules/helpers.py
@@ -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
diff --git a/jenkins_jobs/modules/hipchat_notif.py b/jenkins_jobs/modules/hipchat_notif.py
index a1dbeb42..a77e2bb0 100644
--- a/jenkins_jobs/modules/hipchat_notif.py
+++ b/jenkins_jobs/modules/hipchat_notif.py
@@ -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')
diff --git a/tests/hipchat/fixtures/hipchat003.conf b/tests/hipchat/fixtures/hipchat003.conf
index 93ee35f6..2c61787f 100644
--- a/tests/hipchat/fixtures/hipchat003.conf
+++ b/tests/hipchat/fixtures/hipchat003.conf
@@ -1,4 +1,4 @@
-[hipchat]
+[plugin "hipchat"]
authtoken=blue
send-as=Jenkins
[jenkins]