* Added support for the Jenkins Slack plugin
Change-Id: I0e8d81134d71191a6f0fa3a780f32a06f012969a
This commit is contained in:
parent
d26293fe2f
commit
7e02657f85
@ -36,6 +36,7 @@ import xml.etree.ElementTree as XML
|
||||
|
||||
from jenkins_jobs.errors import InvalidAttributeError
|
||||
from jenkins_jobs.errors import JenkinsJobsException
|
||||
from jenkins_jobs.errors import MissingAttributeError
|
||||
import jenkins_jobs.modules.base
|
||||
|
||||
|
||||
@ -607,6 +608,75 @@ def zeromq_event(parser, xml_parent, data):
|
||||
XML.SubElement(zmq_event, 'enabled').text = 'true'
|
||||
|
||||
|
||||
def slack(parser, xml_parent, data):
|
||||
"""yaml: slack
|
||||
Requires the Jenkins :jenkins-wiki:`Slack Plugin <Slack+Plugin>`
|
||||
|
||||
As the Slack Plugin itself requires a publisher aswell as properties
|
||||
please note that you have to add the publisher to your job configuration
|
||||
aswell.
|
||||
|
||||
:arg bool notify-start: Send notification when the job starts
|
||||
(default: False)
|
||||
:arg bool notify-success: Send notification on success. (default: False)
|
||||
:arg bool notify-aborted: Send notification when job is aborted. (
|
||||
default: False)
|
||||
:arg bool notify-not-built: Send notification when job set to NOT_BUILT
|
||||
status. (default: False)
|
||||
:arg bool notify-unstable: Send notification when job becomes unstable.
|
||||
(default: False)
|
||||
:arg bool notify-failure: Send notification when job fails.
|
||||
(default: False)
|
||||
:arg bool notifiy-back-to-normal: Send notification when job is
|
||||
succeeding again after being unstable or failed. (default: False)
|
||||
:arg bool include-test-summary: Include the test summary. (default:
|
||||
False)
|
||||
:arg bool include-custom-message: Include a custom message into the
|
||||
notification. (default: False)
|
||||
:arg str custom-message: Custom message to be included. (default: '')
|
||||
:arg str room: A comma seperated list of rooms / channels to send
|
||||
the notifications to. (default: '')
|
||||
|
||||
Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/properties/slack001.yaml
|
||||
:language: yaml
|
||||
"""
|
||||
def _add_xml(elem, name, value):
|
||||
if isinstance(value, bool):
|
||||
value = str(value).lower()
|
||||
XML.SubElement(elem, name).text = value
|
||||
|
||||
mapping = (
|
||||
('notify-start', 'startNotification', False),
|
||||
('notify-success', 'notifySuccess', False),
|
||||
('notify-aborted', 'notifyAborted', False),
|
||||
('notify-not-built', 'notifyNotBuilt', False),
|
||||
('notify-unstable', 'notifyUnstable', False),
|
||||
('notify-failure', 'notifyFailure', False),
|
||||
('notify-back-to-normal', 'notifyBackToNormal', False),
|
||||
('include-test-summary', 'includeTestSummary', False),
|
||||
('include-custom-message', 'includeCustomMessage', False),
|
||||
('custom-message', 'customMessage', ''),
|
||||
('room', 'room', ''),
|
||||
)
|
||||
|
||||
slack = XML.SubElement(
|
||||
xml_parent,
|
||||
'jenkins.plugins.slack.SlackNotifier_-SlackJobProperty',
|
||||
)
|
||||
|
||||
# Ensure that custom-message is set when include-custom-message is set
|
||||
# to true.
|
||||
if data.get('include-custom-message', False):
|
||||
if not data.get('custom-message', ''):
|
||||
raise MissingAttributeError('custom-message')
|
||||
|
||||
for yaml_name, xml_name, default_value in mapping:
|
||||
_add_xml(slack, xml_name, data.get(yaml_name, default_value))
|
||||
|
||||
|
||||
def rebuild(parser, xml_parent, data):
|
||||
"""yaml: rebuild
|
||||
Requires the Jenkins :jenkins-wiki:`Rebuild Plugin
|
||||
|
@ -5513,6 +5513,52 @@ def hipchat(parser, xml_parent, data):
|
||||
data['complete-message'])
|
||||
|
||||
|
||||
def slack(parser, xml_parent, data):
|
||||
"""yaml: slack
|
||||
Publisher that sends slack notifications on job events.
|
||||
|
||||
Requires the Jenkins :jenkins-wiki:`Slack Plugin <Slack+Plugin>`
|
||||
|
||||
As the Slack Plugin itself requires a publisher aswell as properties
|
||||
please note that you have to create those too.
|
||||
|
||||
:arg str team-domain: Your team's domain at slack. (default: '')
|
||||
:arg str auth-token: The integration token to be used when sending
|
||||
notifications. (default: '')
|
||||
:arg str build-server-url: Specify the URL for your server installation.
|
||||
(default: '/')
|
||||
:arg str room: A comma seperated list of rooms / channels to post the
|
||||
notifications to. (default: '')
|
||||
Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/publishers/fixtures/slack001.yaml
|
||||
:language: yaml
|
||||
"""
|
||||
def _add_xml(elem, name, value=''):
|
||||
XML.SubElement(elem, name).text = value
|
||||
|
||||
mapping = (
|
||||
('team-domain', 'teamDomain', ''),
|
||||
('auth-token', 'authToken', ''),
|
||||
('build-server-url', 'buildServerUrl', '/'),
|
||||
('room', 'room', ''),
|
||||
)
|
||||
|
||||
slack = XML.SubElement(
|
||||
xml_parent,
|
||||
'jenkins.plugins.slack.SlackNotifier',
|
||||
)
|
||||
|
||||
for yaml_name, xml_name, default_value in mapping:
|
||||
value = data.get(yaml_name, default_value)
|
||||
# All arguments that don't have a default value are mandatory for the
|
||||
# plugin to work as intended.
|
||||
if not value:
|
||||
raise MissingAttributeError(yaml_name)
|
||||
_add_xml(slack, xml_name, value)
|
||||
|
||||
|
||||
def phabricator(parser, xml_parent, data):
|
||||
"""yaml: phabricator
|
||||
Integrate with `Phabricator <http://phabricator.org/>`_
|
||||
|
18
tests/properties/fixtures/slack001.xml
Normal file
18
tests/properties/fixtures/slack001.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<properties>
|
||||
<jenkins.plugins.slack.SlackNotifier_-SlackJobProperty>
|
||||
<startNotification>true</startNotification>
|
||||
<notifySuccess>true</notifySuccess>
|
||||
<notifyAborted>false</notifyAborted>
|
||||
<notifyNotBuilt>false</notifyNotBuilt>
|
||||
<notifyUnstable>false</notifyUnstable>
|
||||
<notifyFailure>false</notifyFailure>
|
||||
<notifyBackToNormal>false</notifyBackToNormal>
|
||||
<includeTestSummary>false</includeTestSummary>
|
||||
<includeCustomMessage>false</includeCustomMessage>
|
||||
<customMessage/>
|
||||
<room>dummy, dummy2</room>
|
||||
</jenkins.plugins.slack.SlackNotifier_-SlackJobProperty>
|
||||
</properties>
|
||||
</project>
|
5
tests/properties/fixtures/slack001.yaml
Normal file
5
tests/properties/fixtures/slack001.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
properties:
|
||||
- slack:
|
||||
room: dummy, dummy2
|
||||
notify-start: true
|
||||
notify-success: true
|
18
tests/properties/fixtures/slack002.xml
Normal file
18
tests/properties/fixtures/slack002.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<properties>
|
||||
<jenkins.plugins.slack.SlackNotifier_-SlackJobProperty>
|
||||
<startNotification>true</startNotification>
|
||||
<notifySuccess>true</notifySuccess>
|
||||
<notifyAborted>true</notifyAborted>
|
||||
<notifyNotBuilt>false</notifyNotBuilt>
|
||||
<notifyUnstable>false</notifyUnstable>
|
||||
<notifyFailure>false</notifyFailure>
|
||||
<notifyBackToNormal>false</notifyBackToNormal>
|
||||
<includeTestSummary>false</includeTestSummary>
|
||||
<includeCustomMessage>true</includeCustomMessage>
|
||||
<customMessage>Custom foo message</customMessage>
|
||||
<room/>
|
||||
</jenkins.plugins.slack.SlackNotifier_-SlackJobProperty>
|
||||
</properties>
|
||||
</project>
|
7
tests/properties/fixtures/slack002.yaml
Normal file
7
tests/properties/fixtures/slack002.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
properties:
|
||||
- slack:
|
||||
notify-start: true
|
||||
notify-success: true
|
||||
notify-aborted: true
|
||||
include-custom-message: true
|
||||
custom-message: 'Custom foo message'
|
11
tests/publishers/fixtures/slack001.xml
Normal file
11
tests/publishers/fixtures/slack001.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<jenkins.plugins.slack.SlackNotifier>
|
||||
<teamDomain>teamname</teamDomain>
|
||||
<authToken>yourauthtoken</authToken>
|
||||
<buildServerUrl>/</buildServerUrl>
|
||||
<room>#builds</room>
|
||||
</jenkins.plugins.slack.SlackNotifier>
|
||||
</publishers>
|
||||
</project>
|
5
tests/publishers/fixtures/slack001.yaml
Normal file
5
tests/publishers/fixtures/slack001.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
publishers:
|
||||
- slack:
|
||||
room: '#builds'
|
||||
team-domain: 'teamname'
|
||||
auth-token: 'yourauthtoken'
|
11
tests/publishers/fixtures/slack002.xml
Normal file
11
tests/publishers/fixtures/slack002.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<jenkins.plugins.slack.SlackNotifier>
|
||||
<teamDomain>teamname</teamDomain>
|
||||
<authToken>yourauthtoken</authToken>
|
||||
<buildServerUrl>http://localhost:8081</buildServerUrl>
|
||||
<room>#builds</room>
|
||||
</jenkins.plugins.slack.SlackNotifier>
|
||||
</publishers>
|
||||
</project>
|
6
tests/publishers/fixtures/slack002.yaml
Normal file
6
tests/publishers/fixtures/slack002.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
publishers:
|
||||
- slack:
|
||||
room: '#builds'
|
||||
team-domain: 'teamname'
|
||||
auth-token: 'yourauthtoken'
|
||||
build-server-url: 'http://localhost:8081'
|
Loading…
Reference in New Issue
Block a user