diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index aef65bf4a..e2f1219c8 100755 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -8332,6 +8332,63 @@ def packer(registry, xml_parent, data): ) +def discord_notifier(registry, xml_parent, data): + """yaml: discord-notifier + This plugin allows for a job to publish results to discord + Requires the Jenkins :jenkins-plugins:`discord-notifier`. + + :arg str webhook-url: Discord webhook URL ( required ) + + Minimal Example: + + .. literalinclude:: + /../../tests/publishers/fixtures/discord-notifier-minimal.yaml + :language: yaml + + Full Example: + + .. literalinclude:: + /../../tests/publishers/fixtures/discord-notifier-full.yaml + :language: yaml + + """ + + boolean_options = { + "send-on-state-change": "sendOnStateChange", + "enable-url-linking": "enableUrlLinking", + "enable-artifact-list": "enableArtifactList", + "enable-footer-info": "enableFooterInfo", + "show-changeset": "showChangeset", + "send-log-file": "sendLogFile", + "send-start-notification": "sendStartNotification", + } + + text_options = { + "webhook-url": "webhookURL", + "branch-name": "branchName", + "status-title": "statusTitle", + "thumbnail-url": "thumbnailURL", + "notes": "notes", + "custom-avatar-url": "customAvatarUrl", + "custom-username": "customUsername", + } + + if data is None: + data = dict() + + notifier = XML.SubElement( + xml_parent, "nz.co.jammehcow.jenkinsdiscord.WebhookPublisher " + ) + notifier.set("plugin", "discord-notifier@1.4.14") + + for (opt, attr) in text_options.items(): + (XML.SubElement(notifier, attr).text) = data.get(opt) + + for (opt, attr) in boolean_options.items(): + value = "true" if data.get(opt, False) else "false" + (XML.SubElement(notifier, attr).text) = value + + class Publishers(jenkins_jobs.modules.base.Base): sequence = 70 diff --git a/tests/publishers/fixtures/discord-notifier-full.conf b/tests/publishers/fixtures/discord-notifier-full.conf new file mode 100644 index 000000000..6d9a01424 --- /dev/null +++ b/tests/publishers/fixtures/discord-notifier-full.conf @@ -0,0 +1,2 @@ +[plugin "discord-notifier"] +param_order_from_yaml = False diff --git a/tests/publishers/fixtures/discord-notifier-full.xml b/tests/publishers/fixtures/discord-notifier-full.xml new file mode 100644 index 000000000..a388099cf --- /dev/null +++ b/tests/publishers/fixtures/discord-notifier-full.xml @@ -0,0 +1,21 @@ + + + + + https://discord.com/api/webhooks/token + branchName + statusTitle + thumbnailURL + notes + customAvatarUrl + customUsername + true + true + true + true + true + true + true + + + diff --git a/tests/publishers/fixtures/discord-notifier-full.yaml b/tests/publishers/fixtures/discord-notifier-full.yaml new file mode 100644 index 000000000..dbae4bf09 --- /dev/null +++ b/tests/publishers/fixtures/discord-notifier-full.yaml @@ -0,0 +1,16 @@ +publishers: + - discord-notifier: + webhook-url: "https://discord.com/api/webhooks/token" + branch-name: "branchName" + status-title: "statusTitle" + thumbnail-url: "thumbnailURL" + notes: "notes" + custom-avatar-url: "customAvatarUrl" + custom-username: "customUsername" + send-on-state-change: true + enable-url-linking: true + enable-artifact-list: true + enable-footer-info: true + show-changeset: true + send-log-file: true + send-start-notification: true diff --git a/tests/publishers/fixtures/discord-notifier-minimal.conf b/tests/publishers/fixtures/discord-notifier-minimal.conf new file mode 100644 index 000000000..6d9a01424 --- /dev/null +++ b/tests/publishers/fixtures/discord-notifier-minimal.conf @@ -0,0 +1,2 @@ +[plugin "discord-notifier"] +param_order_from_yaml = False diff --git a/tests/publishers/fixtures/discord-notifier-minimal.xml b/tests/publishers/fixtures/discord-notifier-minimal.xml new file mode 100644 index 000000000..92402dcd7 --- /dev/null +++ b/tests/publishers/fixtures/discord-notifier-minimal.xml @@ -0,0 +1,21 @@ + + + + + https://discord.com/api/webhooks/token + + + + + + + false + false + false + false + false + false + false + + + diff --git a/tests/publishers/fixtures/discord-notifier-minimal.yaml b/tests/publishers/fixtures/discord-notifier-minimal.yaml new file mode 100644 index 000000000..f1307135c --- /dev/null +++ b/tests/publishers/fixtures/discord-notifier-minimal.yaml @@ -0,0 +1,3 @@ +publishers: + - discord-notifier: + webhook-url: "https://discord.com/api/webhooks/token"