github actions: notifications on workflow failure

Sam*_*fer 6 github github-actions

We have a scheduled github action that fails sometimes. How can I receive email notifications if it fails. At the moment, only the creator of the workflow receives email notifications when it fails.

我的设置

小智 8

你可以在你的行动中尝试这个

- name: Send mail
  if: failure()
  uses: dawidd6/action-send-mail@v2
  with:
    # mail server settings
    server_address: smtp.gmail.com
    server_port: 465
    # user credentials
    username: ${{ secrets.EMAIL_USERNAME }}
    password: ${{ secrets.EMAIL_PASSWORD }}
    # email subject
    subject: ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }}
    # email body as text
    body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }}
    # comma-separated string, send email to
    to: abc@gmail.com,xyz@gmail.com
    # from email name
    from: XYZ
Run Code Online (Sandbox Code Playgroud)

  • `if:always()` 看起来它将在每次执行操作时运行,而不仅仅是在失败时运行,这正是 OP 所要求的 (2认同)