-
Notifications
You must be signed in to change notification settings - Fork 214
68 lines (64 loc) · 1.7 KB
/
notify_slack.yml
File metadata and controls
68 lines (64 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Notify Slack
on:
workflow_call:
inputs:
result:
type: string
required: true
run_id:
type: string
required: false
workflow_name:
type: string
required: true
permissions: {}
jobs:
print_inputs:
timeout-minutes: 2
name: print inputs
runs-on: ubuntu-latest
steps:
- name: print
env:
RUN_ID: ${{ inputs.run_id }}
WORKFLOW_NAME: ${{ inputs.workflow_name }}
RESULT: ${{ inputs.result }}
run: |
echo "$RUN_ID"
echo "$WORKFLOW_NAME"
echo "$RESULT"
notify:
name: Notify Slack Failure
timeout-minutes: 3
runs-on: ubuntu-latest
if: ${{ inputs.result == 'failure' }}
steps:
- name: Slack Notification
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
WORKFLOW_NAME: ${{ inputs.workflow_name }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ inputs.run_id }}
run: |
payload="$(
jq -n \
--arg text "Scheduled Run Failed - $WORKFLOW_NAME" \
--arg run_url "$RUN_URL" \
'{
text: $text,
attachments: [
{
color: "danger",
fields: [
{
title: "URL:",
value: $run_url
}
]
}
]
}'
)"
curl --fail --show-error --silent \
--header "Content-Type: application/json" \
--data "$payload" \
"$SLACK_WEBHOOK_URL"