-
Notifications
You must be signed in to change notification settings - Fork 8
48 lines (41 loc) · 1.59 KB
/
ci_cd_fail_notification.yml
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
name: Notify on Workflow Failure
on:
workflow_run:
workflows: ["Backend CI", "Backend CD", "Frontend CD", "Frontend CI"]
types:
- completed
jobs:
notify:
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
runs-on: ubuntu-latest
steps:
- name: 변수 추출
run: |
SLACK_WEBHOOK_URL=${{ secrets.SLACK_CICD_FAIL_WEBHOOK_URL }}
SLACK_IDS=${{ secrets.SLACK_IDS }}
echo "SLACK_WEBHOOK_URL=$SLACK_WEBHOOK_URL" >> $GITHUB_ENV
echo "SLACK_IDS=$SLACK_IDS" >> $GITHUB_ENV
- name: CI 또는 CD 실패 시 Slack 알람 보내기
run: |
WORKFLOW_NAME="${{ github.event.workflow_run.name }}"
WORKFLOW_URL="${{ github.event.workflow_run.html_url }}"
ASSIGNEE="${{ github.event.workflow_run.actor.login }}"
mentions=""
parse_slack_ids() {
echo "$SLACK_IDS" | jq -r 'to_entries | map("\(.key):\(.value)") | .[]'
}
slack_id=$(parse_slack_ids | grep "^$ASSIGNEE:" | cut -d':' -f2)
if [ -n "$slack_id" ]; then
MENTION="<@$slack_id>"
else
MENTION="$ASSIGNEE"
fi
if [ ! -z "$MENTION" ]; then
message="$MENTION 님, 실행된 $WORKFLOW_NAME 워크플로가 실패했습니다. <$WORKFLOW_URL|확인하러 가기>."
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"$message\"}" \
"$SLACK_WEBHOOK_URL"
echo "Sent message: $message"
else
echo "No MENTIONER to notify"
fi