Add a hook example for sending a Slack message (#2414)

This commit is contained in:
Alex Collins 2019-10-04 14:51:41 -07:00 committed by GitHub
parent dd21ab92ad
commit f116bd3588
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,3 +77,55 @@ field in the spec, which let their respective controllers delete the Job/Workflo
spec:
ttlSecondsAfterFinished: 600
```
## Using A Hook To Send A Slack Message
The following example uses the Slack API to send a a Slack message when sync completes or fails:
```yaml
apiVersion: batch/v1
kind: Job
metadata:
generateName: app-slack-notification-
annotations:
argocd.argoproj.io/hook: PostSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
containers:
- name: slack-notification
image: appropriate/curl
command:
- "curl"
- "-X"
- "POST"
- "--data-urlencode"
- "payload={\"channel\": \"#somechannel\", \"username\": \"hello\", \"text\": \"App Sync succeeded\", \"icon_emoji\": \":ghost:\"}"
- "https://hooks.slack.com/services/..."
restartPolicy: Never
backoffLimit: 2
---
apiVersion: batch/v1
kind: Job
metadata:
generateName: app-slack-notification-fail-
annotations:
argocd.argoproj.io/hook: SyncFail
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
containers:
- name: slack-notification
image: appropriate/curl
command:
- "curl"
- "-X"
- "POST"
- "--data-urlencode"
- "payload={\"channel\": \"#somechannel\", \"username\": \"hello\", \"text\": \"App Sync failed\", \"icon_emoji\": \":ghost:\"}"
- "https://hooks.slack.com/services/..."
restartPolicy: Never
backoffLimit: 2
```