-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed alert msg to be sent to a slack webhook. (#1929)
Created an action that sends a customizable message along with some static information related to the workflow's job it was running. It's currently used in conjunction with if: ${{ failure() }} to send a message to configured webhook as an alert for a failing job, but can be reused for any other purpose, as long as the webhook endpoint accepts the json object that will be sent to. The webhook is free to format the final message accordingly but these are the fields it will receive: { "attempt": "1", "message": "Alert or custom message!", "job_url": "https:/github.com/path/to/workflow/job", "commit_url": "https://github.com/path/to/commit", "repo_url": "https://github.com/path/to/repo" } Where job_url, commit_url and attempt point to the job where the workflow is/was running, the commit_url of the commit that triggered the workflow and the job attempt number respectively. Only the message is customizable by means of the step's "with.message" field. The other fields are internally set by the action. The webhook URL should be stored in a secret and passed to the "with.slack_webook" field of the step.
- Loading branch information
Showing
3 changed files
with
42 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: slack-webhook-sender | ||
description: 'Sends a slack message plus some more workflow job related fields to a slack webhook endpoint.' | ||
inputs: | ||
message: | ||
description: 'Text that will be send in the json .message field.' | ||
required: true | ||
default: 'Hello, world!' | ||
slack_webhook: | ||
description: 'Slack webhook where the data will be posted.' | ||
required: true | ||
default: '' | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Post message data to slack's webhook url. | ||
shell: bash | ||
env: | ||
MESSAGE: ${{ inputs.message }} | ||
REPO_URL: 'https://github.com/${{ github.repository }}' | ||
COMMIT_URL: 'https://github.com/${{ github.repository }}/commit/${{ github.sha }}' | ||
JOB_URL: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}' | ||
ATTEMPT: ${{ github.run_attempt }} | ||
run: | | ||
data="{ \ | ||
\"message\" : \"${MESSAGE}\", \ | ||
\"repo_url\" : \"${REPO_URL}\", \ | ||
\"job_url\" : \"${JOB_URL}\", \ | ||
\"commit_url\": \"${COMMIT_URL}\", \ | ||
\"attempt\" : \"${ATTEMPT}\" \ | ||
}" | ||
echo "Sending alert message data to slack webhook: $(echo $data | jq)" | ||
curl -X POST --data "${data}" -H 'Content-type: application/json; charset=UTF-8' '${{ inputs.slack_webhook }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters