From 8ed66b00a29fa974785e8378c1b5bf5ed454375d Mon Sep 17 00:00:00 2001 From: Alexandre Erwin Ittner Date: Wed, 30 Sep 2020 20:06:32 -0300 Subject: [PATCH] Slack: support custom messages per build result Add support for custom messages per build result in the Slack notification plugin. Change-Id: Iafc8b67528914c6d14c78f72aa535a3cfa7f7033 Story: 2007912 Task: 40315 --- jenkins_jobs/modules/publishers.py | 23 +++++++++--- tests/publishers/fixtures/slack003.xml | 5 +++ tests/publishers/fixtures/slack004.xml | 5 +++ .../fixtures/slack005.plugins_info.yaml | 3 ++ tests/publishers/fixtures/slack005.xml | 35 +++++++++++++++++++ tests/publishers/fixtures/slack005.yaml | 30 ++++++++++++++++ 6 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 tests/publishers/fixtures/slack005.plugins_info.yaml create mode 100644 tests/publishers/fixtures/slack005.xml create mode 100644 tests/publishers/fixtures/slack005.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index e06144ab3..ad09d8dca 100755 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -7629,8 +7629,18 @@ def slack(registry, xml_parent, data): includes commit list with authors and titles (>=2.0). (default "NONE") :arg bool include-custom-message: Include a custom message into the notification (>=2.0). (default false) - :arg str custom-message: Custom message to be included (>=2.0). - (default '') + :arg str custom-message: Custom message to be included for all statuses + (>=2.0). (default '') + :arg str custom-message-success: Custom message for succesful builds + (>=2.10). (default '') + :arg str custom-message-aborted: Custom message for aborted builds + (>=2.10). (default '') + :arg str custom-message-not-built: Custom message for not-built + (>=2.10). (default '') + :arg str custom-message-unstable: Custom message for unstable builds + (>=2.10). (default '') + :arg str custom-message-failure: Custom message for failed builds + (>=2.10). (default '') :arg str auth-token-credential-id: The ID for the integration token from the Credentials plugin to be used to send notifications to Slack. (>=2.1) (default '') @@ -7651,10 +7661,10 @@ def slack(registry, xml_parent, data): /../../tests/publishers/fixtures/slack003.yaml :language: yaml - Full example (version >= 2.0): + Full example (version >= 2.10): .. literalinclude:: - /../../tests/publishers/fixtures/slack004.yaml + /../../tests/publishers/fixtures/slack005.yaml :language: yaml """ @@ -7695,6 +7705,11 @@ def slack(registry, xml_parent, data): ("commit-info-choice", "commitInfoChoice", "NONE"), ("include-custom-message", "includeCustomMessage", False), ("custom-message", "customMessage", ""), + ("custom-message-success", "customMessageSuccess", ""), + ("custom-message-aborted", "customMessageAborted", ""), + ("custom-message-not-built", "customMessageNotBuilt", ""), + ("custom-message-unstable", "customMessageUnstable", ""), + ("custom-message-failure", "customMessageFailure", ""), ("auth-token-credential-id", "authTokenCredentialId", ""), ("bot-user", "botUser", False), ("base-url", "baseUrl", ""), diff --git a/tests/publishers/fixtures/slack003.xml b/tests/publishers/fixtures/slack003.xml index bb4480e8d..8974f11b4 100644 --- a/tests/publishers/fixtures/slack003.xml +++ b/tests/publishers/fixtures/slack003.xml @@ -22,6 +22,11 @@ NONE false + + + + + false diff --git a/tests/publishers/fixtures/slack004.xml b/tests/publishers/fixtures/slack004.xml index 425b33701..f42297c19 100644 --- a/tests/publishers/fixtures/slack004.xml +++ b/tests/publishers/fixtures/slack004.xml @@ -22,6 +22,11 @@ AUTHORS_AND_TITLES true A custom message. + + + + + yourauthtoken true https://hooks.slack.com/services/ diff --git a/tests/publishers/fixtures/slack005.plugins_info.yaml b/tests/publishers/fixtures/slack005.plugins_info.yaml new file mode 100644 index 000000000..10f8f6243 --- /dev/null +++ b/tests/publishers/fixtures/slack005.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'Slack Notification Plugin' + shortName: 'slack' + version: "2.10" diff --git a/tests/publishers/fixtures/slack005.xml b/tests/publishers/fixtures/slack005.xml new file mode 100644 index 000000000..f2f3684fc --- /dev/null +++ b/tests/publishers/fixtures/slack005.xml @@ -0,0 +1,35 @@ + + + + + teamname + yourauthtoken + yourauthtokenid + http://localhost:8081 + #builds + true + true + true + true + true + true + true + true + true + true + true + true + AUTHORS_AND_TITLES + true + A custom message. + A custom message for sucessful builds. + A custom message for aborted builds. + A custom message for not-built. + A custom message for unstable builds. + A custom message for failed builds. + yourauthtoken + true + https://hooks.slack.com/services/ + + + diff --git a/tests/publishers/fixtures/slack005.yaml b/tests/publishers/fixtures/slack005.yaml new file mode 100644 index 000000000..f2ec69dfd --- /dev/null +++ b/tests/publishers/fixtures/slack005.yaml @@ -0,0 +1,30 @@ +publishers: + - slack: + team-domain: 'teamname' + auth-token: 'yourauthtoken' + auth-token-id: 'yourauthtokenid' + build-server-url: 'http://localhost:8081' + room: '#builds' + notify-start: True + notify-success: True + notify-aborted: True + notify-not-built: True + notify-unstable: True + notify-failure: True + notify-every-failure: True + notify-back-to-normal: True + notify-repeated-failure: True + notify-regression: True + include-test-summary: True + include-failed-tests: True + commit-info-choice: 'AUTHORS_AND_TITLES' + include-custom-message: True + custom-message: 'A custom message.' + custom-message-success: 'A custom message for sucessful builds.' + custom-message-aborted: 'A custom message for aborted builds.' + custom-message-not-built: 'A custom message for not-built.' + custom-message-unstable: 'A custom message for unstable builds.' + custom-message-failure: 'A custom message for failed builds.' + auth-token-credential-id: yourauthtoken + bot-user: True + base-url: https://hooks.slack.com/services/