Update Hipchat support to work w/all versions

The HipChat plugin has changed a good bit in version 0.1.9 such that it
is now purely using the publisher hook and it's acquired a few new
configuration items.

This patch ensures used of the existing format will be automatically
redirected to the newer publisher module which adds support for 0.1.9.

Change-Id: I39452e877b20bfc5654d46c90e91dd877a8ebeb0
Story: 2000301
Story: 2000324
This commit is contained in:
Clayton O'Neill 2015-08-03 12:11:18 -04:00 committed by Darragh Bailey
parent 12614f13ab
commit f1bae173ff
4 changed files with 64 additions and 9 deletions

View File

@ -15,6 +15,10 @@
"""
Enable HipChat notifications of build execution.
Supports hipchat plugin versions < 1.9. Will automatically redirect to the
publishers module for newer versions, but still recommended that you convert
to the newer module.
:Parameters:
* **enabled** *(bool)*: general cut off switch. If not explicitly set to
``true``, no hipchat parameters are written to XML. For Jenkins HipChat
@ -49,6 +53,7 @@ Enable HipChat notifications of build execution.
normal after being unstable or failed (Jenkins HipChat plugin >= 0.1.5)
(default false)
Example:
.. literalinclude:: /../../tests/hipchat/fixtures/hipchat001.yaml
@ -117,22 +122,40 @@ class HipChat(jenkins_jobs.modules.base.Base):
return
self._load_global_data()
# convert for compatibility before dispatch
if 'room' in hipchat:
if 'rooms' in hipchat:
logger.warn("Ignoring deprecated 'room' as 'rooms' also "
"defined.")
else:
logger.warn("'room' is deprecated, please use 'rooms'")
hipchat['rooms'] = [hipchat['room']]
plugin_info = self.registry.get_plugin_info("Jenkins HipChat Plugin")
version = pkg_resources.parse_version(plugin_info.get('version', '0'))
properties = xml_parent.find('properties')
if properties is None:
properties = XML.SubElement(xml_parent, 'properties')
pdefhip = XML.SubElement(properties,
'jenkins.plugins.hipchat.'
'HipChatNotifier_-HipChatJobProperty')
if version >= pkg_resources.parse_version("0.1.9"):
publishers = xml_parent.find('publishers')
if publishers is None:
publishers = XML.SubElement(xml_parent, 'publishers')
logger.warn(
"'hipchat' module supports the old plugin versions <1.9, "
"newer versions are supported via the 'publishers' module. "
"Please upgrade you job definition")
return self.registry.dispatch('publisher', parser, publishers,
data)
else:
properties = xml_parent.find('properties')
if properties is None:
properties = XML.SubElement(xml_parent, 'properties')
pdefhip = XML.SubElement(properties,
'jenkins.plugins.hipchat.'
'HipChatNotifier_-HipChatJobProperty')
room = XML.SubElement(pdefhip, 'room')
if 'rooms' in hipchat:
room.text = ",".join(hipchat['rooms'])
elif 'room' in hipchat:
logger.warn("'room' is deprecated, please use 'rooms'")
room.text = hipchat['room']
# Handle backwards compatibility 'start-notify' but all add an element
# of standardization with notify-*

View File

@ -0,0 +1,6 @@
- longName: 'Jenkins HipChat Plugin'
shortName: 'hipchat'
version: "0.1.9"
- longName: 'Derp HipChat Plugin'
shortName: 'hipchat'
version: "0.1.0"

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<jenkins.plugins.hipchat.HipChatNotifier>
<token/>
<room>room1,room2</room>
<startNotification>true</startNotification>
<notifySuccess>false</notifySuccess>
<notifyAborted>false</notifyAborted>
<notifyNotBuilt>false</notifyNotBuilt>
<notifyUnstable>false</notifyUnstable>
<notifyFailure>false</notifyFailure>
<notifyBackToNormal>false</notifyBackToNormal>
<startJobMessage>project_start</startJobMessage>
<completeJobMessage>project_completed</completeJobMessage>
</jenkins.plugins.hipchat.HipChatNotifier>
</publishers>
</project>

View File

@ -0,0 +1,8 @@
hipchat:
enabled: true
rooms:
- room1
- room2
notify-start: true
start-message: "project_start"
complete-message: "project_completed"