Add support for opsgenie notification plugin

Change-Id: Id84b3d9282568cf47d5feb930fd618afe969b45f
This commit is contained in:
John Oram 2019-12-13 11:33:21 -08:00 committed by Thanh Ha
parent 7b00932d2c
commit f760f090fc
No known key found for this signature in database
GPG Key ID: 5783F720616E3180
5 changed files with 89 additions and 0 deletions

47
jenkins_jobs/modules/publishers.py Normal file → Executable file
View File

@ -1311,6 +1311,53 @@ def ftp_publisher(registry, xml_parent, data):
helpers.convert_mapping_to_xml(ftp, data, mapping, fail_required=True)
def opsgenie(registry, xml_parent, data):
"""yaml: opsgenie
OpsGenie notification on build completion,
Requires the :jenkins-wiki:`OpsGenie Notifier Plugin <OpsGenie+Plugin>`.
:arg bool enable-sending-alerts: Send alerts to opsgenie. (default false)
:arg bool notify-build-start: Send a notification when the build starts. (default false)
:arg str api-key: This token is used to verify requests between OpsGenie and Jenkins. You can copy this key from your OpsGenie-Jenkins Integration page. (default '')
:arg str tags: Comma-separated list of tags you want to add on alert. (default '')
:arg str teams: Comma-separated list of teams that get notified from alert. (default '')
:arg str priority: Set the priority of the alert that's going to be created at OpsGenie, if job's build fails. (default 'P3')
:arg str build-starts-alerts-priority: Set the priority of the build started alert that's going to be created at OpsGenie. (default 'P3')
:arg str api-url: Api url that collects the webhook. (default '')
Minimal example:
.. literalinclude::
/../../tests/publishers/fixtures/opsgenie-minimal.yaml
:language: yaml
Full Example:
.. literalinclude::
/../../tests/publishers/fixtures/opsgenie-full.yaml
:language: yaml
"""
mapping = [
("priority", "alertPriority", "P3"),
("build-starts-alerts-priority", "notifyBuildStartPriority", "P3"),
("enable-sending-alerts", "enable", "false"),
("notify-build-start", "notifyBuildStart", "false"),
("api-key", "apiKey", ""),
("api-url", "apiUrl", ""),
("tags", "tags", ""),
("teams", "teams", ""),
]
opsgenie_notifier = XML.SubElement(
xml_parent,
"com.opsgenie.integration.jenkins.OpsGenieNotifier",
{"plugin": "opsgenie"},
)
helpers.convert_mapping_to_xml(opsgenie_notifier, data, mapping, fail_required=True)
def rocket(registry, xml_parent, data):
"""yaml: rocket
RocketChat notification on build completion,

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<com.opsgenie.integration.jenkins.OpsGenieNotifier plugin="opsgenie">
<alertPriority>P1</alertPriority>
<notifyBuildStartPriority>P2</notifyBuildStartPriority>
<enable>true</enable>
<notifyBuildStart>true</notifyBuildStart>
<apiKey>test api key</apiKey>
<apiUrl>another-opsgenie-instance.com</apiUrl>
<tags>a,b,c</tags>
<teams>team a, team b</teams>
</com.opsgenie.integration.jenkins.OpsGenieNotifier>
</publishers>
</project>

View File

@ -0,0 +1,10 @@
publishers:
- opsgenie:
enable-sending-alerts: true
notify-build-start: true
api-key: "test api key"
priority: "P1"
build-starts-alerts-priority: "P2"
api-url: "another-opsgenie-instance.com"
tags: "a,b,c"
teams: "team a, team b"

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<com.opsgenie.integration.jenkins.OpsGenieNotifier plugin="opsgenie">
<alertPriority>P3</alertPriority>
<notifyBuildStartPriority>P3</notifyBuildStartPriority>
<enable>false</enable>
<notifyBuildStart>false</notifyBuildStart>
<apiKey/>
<apiUrl/>
<tags/>
<teams/>
</com.opsgenie.integration.jenkins.OpsGenieNotifier>
</publishers>
</project>

View File

@ -0,0 +1,2 @@
publishers:
- opsgenie