通知

在作业结束或发生某些事情时发送邮件或通道消息


表单的 notifications 规定了谁会收到其作业的消息,以及何时收到:

  • 谁: recipients ,即邮件地址;以及 channels ,即 通知通道的名称(邮件、Slack、Microsoft Teams、Telegram、webhook)。两者 至少需要其一。
  • 何时: onStatus ,在作业结束时( success 、 failed 、 aborted 、 warning 或 any );以及 onEvent ,在 作业发生某些事情时( launch 、 relaunch 、 delete 、 approve 、 reject 或 any )。
notifications:
  recipients:
    - ops@example.com
  channels:
    - ops-teams
  onStatus:
    - failed
  onEvent:
    - approve
    - reject

When you want to send a notification on job-event: an email, and a message to notification channels (Connections > Notifications: Slack, Microsoft Teams, Telegram, a webhook)

Email Templates
Notification emails use HTML templates located in server/templates/email/:

  • approval.html - Approval request notifications
  • jobstatus.html - Job outcome notifications (success, failed, aborted, warning)
  • jobevent.html - Job lifecycle event notifications (launch, relaunch, delete, approve, reject)

    These templates can be customized by replacing them with your own versions.
    In Docker or Kubernetes deployments, mount your custom templates to /app/dist/templates/email/ to override the defaults.
    Example Docker mount: -v /path/to/custom/templates:/app/dist/templates/email/
    A mount at the former location, /app/dist/src/templates/, keeps working and takes precedence.

属性

notifications 对象的属性:

属性 说明
recipients
array

Recipients
email address

A list of email addresses who need to receive a notification.
recipients or channels, or both, is needed.

channels
array

Channels
the name of a notification channel

The notification channels of Connections > Notifications the notification goes to: Slack, Microsoft Teams, Telegram, a webhook. They get a short message (the form, the job, what happened) with a link to the job.
A mail channel in this list sends the notification mail to the recipients through that server instead of the active one.
A name that is not there is said in the log and skipped. (Added in 7.0.0)

onStatus
array

Jobstatus event

A list of jobstatus events you want to send a notification on. Use any, if you always want a notification.
At least one of onStatus or onEvent must be specified for notifications to be sent.

选项:
  • any
  • success
  • failed
  • aborted
  • warning
onEvent
array

Job trigger events

A list of job lifecycle events (triggers) you want to send a notification on.
Unlike onStatus which notifies on job outcomes, onEvent notifies on user actions and job lifecycle events.
Use any to be notified of all job events.

选项:
  • any
  • launch
  • relaunch
  • delete
  • approve
  • reject

示例

通知示例(YAML):

1) Send a notification on failed

定义(YAML):

notifications:
  recipients:
    - info@ansibleguy.com
  onStatus:
    - failed

2) Send notifications on job events (launch, relaunch, approve, reject)

定义(YAML):

notifications:
  recipients:
    - admin@ansibleguy.com
    - auditor@ansibleguy.com
  onEvent:
    - launch
    - relaunch
    - approve
    - reject

3) Send notifications on all events

定义(YAML):

notifications:
  recipients:
    - admin@ansibleguy.com
  onStatus:
    - any
  onEvent:
    - launch
    - relaunch
    - delete
    - approve
    - reject