Skip to content

Latest commit

 

History

History
82 lines (71 loc) · 3.15 KB

slack.md

File metadata and controls

82 lines (71 loc) · 3.15 KB

Configuration

  1. Create Slack Application using https://api.slack.com/apps?new_app=1 1

  2. Once application is created navigate to Enter OAuth & Permissions 2

  3. Click Permissions under Add features and functionality section and add chat:write scope. To use the optional username and icon overrides in the Slack notification service also add the chat:write.customize scope. 3

  4. Scroll back to the top, click 'Install App to Workspace' button and confirm the installation. 4

  5. Once installation is completed copy the OAuth token. 5

  6. Create a public or private channel, for this example my_channel

  7. Invite your slack bot to this channel otherwise slack bot won't be able deliver notifications to this channel

  8. Store Oauth access token in argocd-notifications-secret secret

apiVersion: v1
kind: Secret
metadata:
  name: <secret-name>
stringData:
  slack-token: <Oauth-access-token>
  1. Define service type slack in data section of argocd-notifications-cm configmap: service
apiVersion: v1
kind: ConfigMap
metadata:
  name: <config-map-name>
data:
  **service.slack**: |
    apiURL: <url>                 # optional URL, e.g. https://example.com/api
    token: $**slack-token**
    username: <override-username> # optional username
    icon: <override-icon> # optional icon for the message (supports both emoij and url notation)
  1. 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

Templates

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
        }]
      }]