Skip to content

Templates

The notification template is used to generate the notification content and configured in argocd-notifications-cm ConfigMap. The template is leveraging html/template golang package and allow to customize notification message. Templates are meant to be reusable and can be referenced by multiple triggers.

The following template is used to notify the user about application sync status.

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
data:
  template.my-custom-template-slack-template: |
    message: |
      Application {{.app.metadata.name}} sync is {{.app.status.sync.status}}.
      Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.

Each template has access to the following fields:

  • app holds the application object.
  • context is user defined string map and might include any string keys and values.
  • serviceType holds the notification service type name. The field can be used to conditionally render service specific fields.
  • recipient holds the recipient name.

Notification Service Specific Fields

The message field of the template definition allows creating a basic notification for any notification service. You can leverage notification service-specific 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. See correspondingĀ service documentation for more information.

Functions

Templates have access to the set of built-in functions:

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-notifications-cm
data:
  template.my-custom-template-slack-template: |
    message: "Author: {{(call .repo.GetCommitMetadata .app.status.sync.revision).Author}}"

time

Time related functions.


time.Now() Time

Executes function built-in Golang time.Now function. Returns an instance of Golang Time.


time.Parse(val string) Time

Parses specified string using RFC3339 layout. Returns an instance of Golang Time.

repo

Functions that provide additional information about Application source repository.


repo.RepoURLToHTTPS(url string) string

Transforms given GIT URL into HTTPs format.


repo.FullNameByRepoURL(url string) string

Returns repository URL full name (<owner>/<repoName>). Currently supports only Github, Gitlab and Bitbucket.


repo.GetCommitMetadata(sha string) CommitMetadata

Returns commit metadata. The commit must belong to the application source repository. CommitMetadata fields:

  • Message string commit message
  • Author string - commit author
  • Date time.Time - commit creation date
  • Tags []string - Associated tags