diff --git a/.azure-pipelines/templates/stages/notify-stage.yml b/.azure-pipelines/templates/stages/notify-stage.yml index 45f5f6411..9498901f9 100644 --- a/.azure-pipelines/templates/stages/notify-stage.yml +++ b/.azure-pipelines/templates/stages/notify-stage.yml @@ -1,16 +1,32 @@ stages: - - stage: Notify + - stage: NotifySuccess jobs: - - job: notify release build success + - job: notify_release_build_success pool: vmImage: ubuntu-latest steps: - task: DownloadSecureFile@1 name: webhook_url inputs: - secureFile: mattermost_webhook_url_release_success + secureFile: mattermost_webhook_url_release_notify - bash: | set -e AUTHOR_NAME="$(git log -1 --pretty=format:'%an')" - "${BUILD_REPOSITORY_LOCALPATH}/tools/notify_mattermost.py" "${AUTHOR_NAME}" $(webhook_url.secureFilePath) - displayName: Send mattermost message + "${BUILD_REPOSITORY_LOCALPATH}/tools/notify_mattermost.py" "${AUTHOR_NAME}" $(webhook_url.secureFilePath) SUCCESS + displayName: Send mattermost success message + - stage: NotifyFailure + condition: failed() + jobs: + - job: notify_release_build_failure + pool: + vmImage: ubuntu-latest + steps: + - task: DownloadSecureFile@1 + name: webhook_url + inputs: + secureFile: mattermost_webhook_url_release_notify + - bash: | + set -e + AUTHOR_NAME="$(git log -1 --pretty=format:'%an')" + "${BUILD_REPOSITORY_LOCALPATH}/tools/notify_mattermost.py" "${AUTHOR_NAME}" $(webhook_url.secureFilePath) FAILURE + displayName: Send mattermost failure message diff --git a/tools/notify_mattermost.py b/tools/notify_mattermost.py index c15ed433a..275bd1776 100755 --- a/tools/notify_mattermost.py +++ b/tools/notify_mattermost.py @@ -4,20 +4,14 @@ Script to notify the person doing the release that the Azure run was successful. Run: -python tools/notify_mattermost.py GITHUB_AUTHOR_NAME MATTERMOST_WEBHOOK_URL +python tools/notify_mattermost.py GITHUB_AUTHOR_NAME MATTERMOST_WEBHOOK_URL STATUS + +where STATUS is either SUCCESS or FAILURE """ import random import requests import sys -# This should be a mattermost webhook url that posts to a specific channel, -# created by certbotbot, with a file containing the url saved in azure pipelines secret -# files, under pipelines > library. The secret file will need to be given permission to -# be used by the specific pipeline, in this case 'release.' -url_path = sys.argv[2] -with open(url_path, 'r') as file: - url = file.read().rstrip() - # We use github author here because it's what we have access to. If the name sometimes # changes, add any name it might be. Check the git log. requested_for = sys.argv[1].rstrip() @@ -28,6 +22,16 @@ usernames_map = { 'ohemorange': 'erica', } +# This should be a mattermost webhook url that posts to a specific channel, +# created by certbotbot, with a file containing the url saved in azure pipelines secret +# files, under pipelines > library. The secret file will need to be given permission to +# be used by the specific pipeline, in this case 'release.' +url_path = sys.argv[2] +with open(url_path, 'r') as file: + url = file.read().rstrip() + +status = sys.argv[3].rstrip() + headers = { 'Content-Type': 'application/json', } @@ -39,21 +43,31 @@ fun_greetings = [ 'Pinging', ] -fun_messages = [ - 'the certbot release is ready to come out of the oven', - "it's release-finishing go time", - 'all certbot release systems are set for launch', +fun_success_messages = [ + 'the certbot release is ready to come out of the oven!', + "it's release-finishing go time!", + 'all certbot release systems are set for launch!', ] +if status == 'SUCCESS': + message = random.choice(fun_success_messages) +elif status == 'FAILURE': + message = "the release pipeline has failed." +else: + raise RuntimeError("STATUS must be either SUCCESS or FAILURE") + + +azure_url = 'https://dev.azure.com/certbot/certbot/_build?definitionId=3' + + greeting = random.choice(fun_greetings) -message = random.choice(fun_messages) if requested_for in usernames_map: - text_body = f'{greeting} @{usernames_map[requested_for]}, {message}!' + text_body = f'{greeting} @{usernames_map[requested_for]}, {message}\n{azure_url}' else: - text_body = (f"{greeting} {requested_for}, {message}! If you'd like to get @ mentioned for " + text_body = (f"{greeting} {requested_for}, {message} If you'd like to get @ mentioned for " "releases you do in the future, please modify tools/notify_mattermost.py with your " - "git author name.") + f"git author name.\n{azure_url}") content = { 'text': text_body,