If you want to send message using incoming webhook, you can use webhook.
The Slack notification service configuration includes following settings:
token
- the app tokenapiURL
- optional, the server url, e.g. https://example.com/apiusername
- optional, the app usernameicon
- optional, the app icon, e.g. :robot_face: or https://example.com/image.pnginsecureSkipVerify
- optional bool, true or false
-
Create Slack Application using https://api.slack.com/apps?new_app=1
-
Once application is created navigate to
Enter OAuth & Permissions
-
Click
Permissions
underAdd features and functionality
section and addchat:write
scope. To use the optional username and icon overrides in the Slack notification service also add thechat:write.customize
scope. -
Scroll back to the top, click 'Install App to Workspace' button and confirm the installation.
-
Create a public or private channel, for this example
my_channel
-
Invite your slack bot to this channel otherwise slack bot won't be able to deliver notifications to this channel
-
Store Oauth access token in
argocd-notifications-secret
secretapiVersion: v1 kind: Secret metadata: name: <secret-name> stringData: slack-token: <Oauth-access-token>
-
Define service type slack in data section of
argocd-notifications-cm
configmap: serviceapiVersion: v1 kind: ConfigMap metadata: name: <config-map-name> data: service.slack: | token: $slack-token
-
Add annotation in application yaml file to enable notifications for specific argocd app
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: annotations: notifications.argoproj.io/subscribe.on-sync-succeeded.slack: my_channel
Notification templates can be customized to leverage slack message blocks and attachments feature.
The message blocks and attachments can be specified in blocks
and attachments
string fields under slack
field:
template.app-sync-status: |
message: |
Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}.
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
slack:
attachments: |
[{
"title": "{{.app.metadata.name}}",
"title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
"color": "#18be52",
"fields": [{
"title": "Sync Status",
"value": "{{.app.status.sync.status}}",
"short": true
}, {
"title": "Repository",
"value": "{{.app.spec.source.repoURL}}",
"short": true
}]
}]
The messages can be aggregated to the slack threads by grouping key which can be specified in a groupingKey
string field under slack
field.
groupingKey
is used across each template and works independently on each slack channel.
When multiple applications will be updated at the same time or frequently, the messages in slack channel can be easily read by aggregating with git commit hash, application name, etc.
Furthermore, the messages can be broadcast to the channel at the specific template by notifyBroadcast
field.
template.app-sync-status: |
message: |
Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}.
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
slack:
attachments: |
[{
"title": "{{.app.metadata.name}}",
"title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
"color": "#18be52",
"fields": [{
"title": "Sync Status",
"value": "{{.app.status.sync.status}}",
"short": true
}, {
"title": "Repository",
"value": "{{.app.spec.source.repoURL}}",
"short": true
}]
}]
# Aggregate the messages to the thread by git commit hash
groupingKey: "{{.app.status.sync.revision}}"
notifyBroadcast: false
template.app-sync-failed: |
message: |
Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}.
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
slack:
attachments: |
[{
"title": "{{.app.metadata.name}}",
"title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
"color": "#ff0000",
"fields": [{
"title": "Sync Status",
"value": "{{.app.status.sync.status}}",
"short": true
}, {
"title": "Repository",
"value": "{{.app.spec.source.repoURL}}",
"short": true
}]
}]
# Aggregate the messages to the thread by git commit hash
groupingKey: "{{.app.status.sync.revision}}"
notifyBroadcast: true