【问题标题】:Xcode Server Bot not sending email reportsXcode Server Bot 不发送电子邮件报告
【发布时间】:2021-05-06 18:31:33
【问题描述】:

我在本地 iMac 上运行 Xcode Server Bots,但没有发送电子邮件通知。

我已经学习了很多教程,并且有 postfix 设置和工作。我可以使用命令成功发送电子邮件

sudo echo "Test sending email from Postfix" | mail -s "Test Postfix" xxxxxx@me.com

我的电子邮件已收到。

Xcode > Preferences > Server & Bots > Mail 下我按照所有教程将所有内容留空。

对于我的机器人,在Triggers 下,我有一个Periodic Email ReportSchedule 设置为After each integration,并设置我的fromreply-toTo 字段并勾选每个Notify On

我使用命令监控smtpsmtp进程

sudo log stream --predicate  '(process == "smtpd") || (process == "smtp")' --info

当我使用上述测试发送电子邮件时,会显示一条日志行。

但是,当我的 Xcode Bot 完成时,我什么也得不到。 Bot 日志显示

Feb  2 13:47:16  [596] <Info>: Executing trigger 'Periodic Email Report'
Feb  2 13:47:16  [596] <Info>: Executing trigger 'New Issue Email'

因此电子邮件报告不会触发任何类型的smtp。它甚至使用后缀吗?我可以记录其他内容以查看它是否达到了postfix 吗?

编辑 ------

我发现一些 sendmail 日志似乎显示 Xcode 没有使用 postdrop 的正确权限:

kernel    Sandbox: sendmail(48548) deny(1) forbidden-exec-sugid
sendmail    fatal: execvp /usr/sbin/postdrop: Operation not permitted
sendmail    warning: command "/usr/sbin/postdrop -r" exited with status 1
sendmail    fatal: xcode@<redacted>.com(450): unable to execute /usr/sbin/postdrop -r: Undefined error: 0

与我在网上找到的相比,我的postdrop 权限似乎是正确的:

-rwxr-xr-x    1 root   wheel        570448  1 Jan  2020 postalias
-rwxr-xr-x    1 root   wheel        466416  1 Jan  2020 postcat
-rwxr-xr-x    1 root   wheel        823488  1 Jan  2020 postconf
-rwxr-sr-x    1 root   _postdrop    588624  1 Jan  2020 postdrop
-rwxr-xr-x    1 root   wheel        431904  1 Jan  2020 postfix
-rwxr-xr-x    1 root   wheel        432032  1 Jan  2020 postkick
-rwxr-xr-x    1 root   wheel        449424  1 Jan  2020 postlock
-rwxr-xr-x    1 root   wheel        431872  1 Jan  2020 postlog
-rwxr-xr-x    1 root   wheel        569632  1 Jan  2020 postmap
-rwxr-xr-x    1 root   wheel        465872  1 Jan  2020 postmulti
-rwxr-sr-x    1 root   _postdrop    588448  1 Jan  2020 postqueue
-rwxr-xr-x    1 root   wheel        466784  1 Jan  2020 postsuper

我的/etc/group 文件中有_postdrop 用户:

_postdrop:*:28:

还是我读错了? sendmail用户是否需要postdrop的使用权限?

编辑 2 --------

这似乎是Big Sur 使根分区只读的问题。 sudo postfix set-permissions 做不到。

所以我想现在的问题是,如何为 Xcode Server 安装/使用不同的方法来发送电子邮件?

【问题讨论】:

  • This 将有助于发送电子邮件报告触发器。
  • 很遗憾没有。我确认我可以从命令行发送邮件,它显示了smtp 日志,但是 Xcode 日志显示它正在执行电子邮件触发器,但根本没有任何东西通过 smtp。
  • @Darren 你查看我编辑的答案了吗?
  • @zeytin 是的。虽然我不能接受它作为正确答案,但我会奖励你的努力。我今天找到了一种从 Xcode 发送电子邮件的方法,并将在更多测试后尽快发布。
  • @Darren 没关系,期待你的帖子,谢谢!

标签: xcode email postfix-mta xcode-server xcode-bots


【解决方案1】:

经过大量研究,在别处提出问题并反复试验,似乎它只是行不通。在某个地方,Xcode 服务器没有自动发送电子邮件的正确权限。这可能是 Xcode Server 甚至 Big Sur 中的错误。

sendmail 本身是一个非常难以设置的野兽,但如果您按照许多教程中的建议从命令行运行它,那么您可以通过一种方法从 Xcode 服务器获取电子邮件。

Apple forums上的一位成员的建议下,似乎使用Post Integration Script实际上可以直接调用sendmail。所以我想出了以下脚本:

将此添加为后集成脚本:更改保存以下 2 个文件的路径。

#!/bin/sh

SCRIPT="/Users/darren/Desktop/mail.sh"
echo "Executing script $SCRIPT"
source $SCRIPT

email.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-GB">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>%%XCS_BOT_NAME%%</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

  <style type="text/css">
    a[x-apple-data-detectors] {color: inherit !important;}
  </style>

</head>
<body style="margin: 0; padding: 0;">
  <table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td style="padding: 20px 0 30px 0;">

        <table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="border-collapse: collapse; border: 1px solid #cccccc;">
          <tr>
            <td align="center" bgcolor="%%COLOUR%%" style="padding: 40px 0 30px 0;">
              Integration #%%XCS_INTEGRATION_NUMBER%% of %%XCS_BOT_NAME%% Bot %%RESULT%%
            </td>
          </tr>
          <tr>
            <td bgcolor="#ffffff" style="padding: 40px 30px 40px 30px;">
              <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse;">
                <tr>
                  <td style="color: #153643; font-family: Arial, sans-serif;">
                    <h1 style="font-size: 24px; margin: 0;">Latest commit</h1>
                  </td>
                </tr>
                <tr>
                  <td style="color: #153643; font-family: Arial, sans-serif; font-size: 16px; line-height: 24px; padding: 20px 0 30px 0;">
                    <p style="margin: 0;">%%LATESTMERGE%%</p>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>

ma​​il.sh 根据需要编辑 4 个变量。你可能需要chmod +x mail.sh这个文件。

#!/bin/sh

# Customise these fields
TO_EMAIL="youremail@me.com"
FROM_EMAIL="xcode@whatever_you_setup_in_sendmail.com"
EMAILTEMPLATE=$(</Users/darren/Desktop/email.html) # $(<path/to/email.html) don't forget the < before the path
EMAIL_AFTER_EVERY_INTEGRATION=1 # true=1/false=0 | 0 will only email on failures/warnings

# Result colour
COLOUR='#888881'
if [[ $XCS_INTEGRATION_RESULT == 'warnings' ]] || [[ $XCS_INTEGRATION_RESULT == 'analyzer-warnings' ]]; then
    COLOUR='#D9CE1F'
elif [[ $XCS_INTEGRATION_RESULT == 'test-failures' ]] || [[ $XCS_INTEGRATION_RESULT == 'build-errors' ]]; then
    COLOUR='#C03636'
elif [[ $XCS_INTEGRATION_RESULT == 'succeeded' ]]; then
    if [ $EMAIL_AFTER_EVERY_INTEGRATION == 0 ]; then
        exit 0
    fi
    COLOUR='#83BC39'
elif [[ $XCS_INTEGRATION_RESULT == 'canceled' ]]; then
    COLOUR='#888881'
fi

# Result
RESULT="Unknown result ${XCS_INTEGRATION_RESULT}"
if [[ ${XCS_INTEGRATION_RESULT} == "succeeded" ]]; then
    RESULT="Succeeded"
elif [[ ${XCS_INTEGRATION_RESULT} == "canceled" ]]; then
    RESULT="was Cancelled"
elif [[ ${XCS_INTEGRATION_RESULT} == "warnings" ]]; then
    if [[ ${XCS_WARNING_COUNT} == 1 ]]; then
        RESULT="Has 1 Warning"
    else
        RESULT="Has ${XCS_WARNING_COUNT} Warnings"
    fi
elif [[ ${XCS_INTEGRATION_RESULT} == "analyzer-warnings" ]]; then
    if [[ ${XCS_ANALYZER_WARNING_COUNT} == 1 ]]; then
        RESULT="Has 1 Warning"
    else
        RESULT="Has ${XCS_ANALYZER_WARNING_COUNT} Warnings"
    fi
elif [[ ${XCS_INTEGRATION_RESULT} == "test-failures" ]]; then
    if [[ ${XCS_TEST_FAILURE_COUNT} == 1 ]]; then
        RESULT="Failed 1 Test"
    else
        RESULT="Failed ${XCS_TEST_FAILURE_COUNT} Tests"
    fi
elif [[ ${XCS_INTEGRATION_RESULT} == "build-errors" ]]; then
    if [[ ${XCS_ERROR_COUNT} == 1 ]]; then
        RESULT="Failed with 1 Error"
    else
        RESULT="Failed with ${XCS_ERROR_COUNT} Errors"
    fi
fi

SUBJECT="$RESULT"

# If not null/empty
if [ -n "${XCS_PRIMARY_REPO_DIR}" ]; then
    LATESTMERGE="$(cd $XCS_PRIMARY_REPO_DIR && git log -1)"
else
    LATESTMERGE="Invalid repo $XCS_PRIMARY_REPO_DIR"
fi

# Replace contents of email
EMAILTEMPLATE="${EMAILTEMPLATE//%%COLOUR%%/$COLOUR}"
EMAILTEMPLATE="${EMAILTEMPLATE//%%XCS_BOT_NAME%%/${XCS_BOT_NAME}}"
EMAILTEMPLATE="${EMAILTEMPLATE//%%XCS_INTEGRATION_NUMBER%%/${XCS_INTEGRATION_NUMBER}}"
EMAILTEMPLATE="${EMAILTEMPLATE//%%RESULT%%/$RESULT}"
EMAILTEMPLATE="${EMAILTEMPLATE//%%LATESTMERGE%%/$LATESTMERGE}"

# echo $EMAILTEMPLATE

echo "Sending report to $TO_EMAIL"

# Send email directly through sendmail
(  
echo "From: $FROM_EMAIL"  
echo "To: $TO_EMAIL"  
echo "MIME-Version: 1.0"  
echo "Subject: $SUBJECT"   
echo "Content-Type: text/html"   
echo $EMAILTEMPLATE  
) | /usr/sbin/sendmail -t

您现在将收到如下电子邮件:

如果有人知道他,我们可以添加实际的失败原因或错误,这将是很棒的。我们可以使用here 的变量列表,我认为这可能涉及查看实际的构建路径。

【讨论】:

  • 好东西,达伦!感谢您进行研究并分享!我希望苹果对他们的开发工具更加关注:)
【解决方案2】:

您的过程是完全正确的,但只有一个例外。正如您指出并记录所说,权限存在问题。

如果rpm -qV postfixpostfix check 完整的日志可以很好地分享以深入解决问题,但您已经有一些日志声明 Xcode 没有权限。

您还可以使用您的电子邮件机器人来找出“在 Xcode 报告导航器中管理机器人”。这是Apple Document

我认为这将有助于设置权限:

sudo mkdir -p /Library/Server/Mail/Data/Spool
sudo /usr/sbin/postfix set-permissions
sudo /usr/sbin/postfix start

运行后清除 postprop 以进行仔细检查

$ sudo killall postdrop

编辑1: 或者,如果仍然无法正常工作,试试这个命令是个好主意

sudo /etc/init.d/postfix stop
sudo killall -9 postdrop

设置权限:

sudo chown postfix:postdrop /var/spool/postfix/maildrop
sudo chmod 1730 /var/spool/postfix/maildrop

重启后缀:

sudo /etc/init.d/postfix start

在最后阶段,应该会收到这样的电子邮件:


最终编辑

我的第一个和 Edit1 答案不适用于 PO。

有一些旧线程表明这可能是不同 MacOS 版本的错误。就后缀而言,Big Sur 似乎存在问题。

Thread1

Thread2

【讨论】:

  • 感谢您的帮助。看来我在使用 set-permissions 命令时遇到了问题。它给出了错误chown: /usr/libexec/postfix: Operation not permitted 我也在安全模式下尝试过。
  • 不客气。我找到了这个并编辑了我的答案:unix.stackexchange.com/questions/471821/…
  • 我认为这可能与大苏尔有关。我发现这个discussions.apple.com/thread/7933518 来解决Operation not permitted 问题。我已禁用 SIP,但现在我收到错误 chown: /usr/libexec/postfix: Read-only file system,即使我尝试手动更改 post drop 文件的权限。
  • Big Sur 不允许修改根文件系统。我已按照步骤安装它twitter.com/EBADTWEET/status/1275454103900971012,但在运行set-permissions 时仍然出现Operation not permitted 错误
  • 你说得对,我将按照这个问题,希望你找到准确而简短的解决方案。
【解决方案3】:

我对 Xcode 不太熟悉,但您描述的问题显然是 Xcode 应用程序和您的 Postfix SMTP 服务器之间的通信。 我会尝试以下方法:

  1. 获取 Xcode 日志。

  2. 获取 Postfix 日志。

    • 同样,这些可以在 Console.app 中找到,因为它们应该由 ASL 创建(即 macOS 的系统日志)
    • 此外,您可以指定您自己的日志文件,如 Postfix 网站上的文档所述:http://www.postfix.org/MAILLOG_README.html

希望通过这样做,您能够查看您配置的邮件更新是否在 Xcode 之外并到达您的 Postfix 服务器。

【讨论】:

  • 感谢您的帮助。我设法找到了日志,看来这可能是权限问题。我已将日志附加到我上面的问题中。谢谢
猜你喜欢
  • 2012-05-07
  • 2019-04-17
  • 1970-01-01
  • 1970-01-01
  • 2013-02-18
  • 2012-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多