github.com/argoproj/argo-cd/v2@v2.10.9/docs/operator-manual/notifications/templates.md (about) 1 The notification template is used to generate the notification content and is configured in the `argocd-notifications-cm` ConfigMap. The template is leveraging 2 the [html/template](https://golang.org/pkg/html/template/) golang package and allows customization of the notification message. 3 Templates are meant to be reusable and can be referenced by multiple triggers. 4 5 The following template is used to notify the user about application sync status. 6 7 ```yaml 8 apiVersion: v1 9 kind: ConfigMap 10 metadata: 11 name: argocd-notifications-cm 12 data: 13 template.my-custom-template-slack-template: | 14 message: | 15 Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}. 16 Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}. 17 ``` 18 19 Each template has access to the following fields: 20 21 - `app` holds the application object. 22 - `context` is a user-defined string map and might include any string keys and values. 23 - `secrets` provides access to sensitive data stored in `argocd-notifications-secret` 24 - `serviceType` holds the notification service type name (such as "slack" or "email). The field can be used to conditionally 25 render service-specific fields. 26 - `recipient` holds the recipient name. 27 28 ## Defining user-defined `context` 29 30 It is possible to define some shared context between all notification templates by setting a top-level 31 YAML document of key-value pairs, which can then be used within templates, like so: 32 33 ```yaml 34 apiVersion: v1 35 kind: ConfigMap 36 metadata: 37 name: argocd-notifications-cm 38 data: 39 context: | 40 region: east 41 environmentName: staging 42 43 template.a-slack-template-with-context: | 44 message: "Something happened in {{ .context.environmentName }} in the {{ .context.region }} data center!" 45 ``` 46 47 ## Defining and using secrets within notification templates 48 49 Some notification service use cases will require the use of secrets within templates. This can be achieved with the use of 50 the `secrets` data variable available within the templates. 51 52 Given that we have the following `argocd-notifications-secret`: 53 54 ```yaml 55 apiVersion: v1 56 kind: Secret 57 metadata: 58 name: argocd-notifications-secret 59 stringData: 60 sampleWebhookToken: secret-token 61 type: Opaque 62 ``` 63 64 We can use the defined `sampleWebhookToken` in a template as such: 65 66 ```yaml 67 apiVersion: v1 68 kind: ConfigMap 69 metadata: 70 name: argocd-notifications-cm 71 data: 72 template.trigger-webhook: | 73 webhook: 74 sample-webhook: 75 method: POST 76 path: 'webhook/endpoint/with/auth' 77 body: 'token={{ .secrets.sampleWebhookToken }}&variables[APP_SOURCE_PATH]={{ .app.spec.source.path }} 78 ``` 79 80 ## Notification Service Specific Fields 81 82 The `message` field of the template definition allows creating a basic notification for any notification service. You can leverage notification service-specific 83 fields to create complex notifications. For example using service-specific you can add blocks and attachments for Slack, subject for Email or URL path, and body for Webhook. 84 See corresponding service [documentation](services/overview.md) for more information. 85 86 ## Change the timezone 87 88 You can change the timezone to show in notifications as follows. 89 90 1. Call time functions. 91 92 ``` 93 {{ (call .time.Parse .app.status.operationState.startedAt).Local.Format "2006-01-02T15:04:05Z07:00" }} 94 ``` 95 96 2. Set the `TZ` environment variable on the argocd-notifications-controller container. 97 98 ```yaml 99 apiVersion: apps/v1 100 kind: Deployment 101 metadata: 102 name: argocd-notifications-controller 103 spec: 104 template: 105 spec: 106 containers: 107 - name: argocd-notifications-controller 108 env: 109 - name: TZ 110 value: Asia/Tokyo 111 ``` 112 113 ## Functions 114 115 Templates have access to the set of built-in functions: 116 117 ```yaml 118 apiVersion: v1 119 kind: ConfigMap 120 metadata: 121 name: argocd-notifications-cm 122 data: 123 template.my-custom-template-slack-template: | 124 message: "Author: {{(call .repo.GetCommitMetadata .app.status.sync.revision).Author}}" 125 ``` 126 127 {!docs/operator-manual/notifications/functions.md!}