Xcode服务器机器人未发送电子邮件报告

4

我在我的本地iMac上运行Xcode服务器机器人,但邮件通知未能发送。

我已经跟随了许多教程,并完成了postfix的设置和工作。我可以使用命令成功发送电子邮件。

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

我已经收到了我的电子邮件。

Xcode > Preferences > Server & Bots > Mail 中,根据所有教程的建议,我把所有内容都留空了。

对于我的 bot,在 Triggers 下,我设置了一个 定期电子邮件报告Schedule 设置为 每次集成后,并设置了我的 fromreply-toTo 字段,并选中了每个 Notify On 选框。

enter image description here

我使用以下命令监视 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?我能记录其他内容以查看是否完全命中了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服务器发送电子邮件?


这将有助于发送电子邮件报告触发器。 - Raksha Saini
1
很遗憾,我确认我可以从命令行发送邮件并显示smtp日志,但是Xcode日志显示正在执行电子邮件触发器,但是没有任何内容通过smtp传递。 - Darren
@Darren,你看过我编辑后的答案了吗? - zeytin
@zeytin 是的。虽然我不能把它作为正确答案接受,但我会授予你赏金以表彰你的努力。我今天找到了一种从Xcode发送电子邮件的方法,并将在进行更多测试后很快发布它。 - Darren
@Darren 没问题,期待你的帖子,谢谢! - zeytin
答案已添加下方。 - Darren
4个回答

3
经过大量研究、在其他地方提问和实验,似乎它根本行不通。在某个地方,Xcode服务器没有发送电子邮件的正确权限。这可能是Xcode服务器或Big Sur中的一个错误。 sendmail 本身就是一个很难设置的野兽,但如果您已经像许多教程中建议的那样从命令行获得了它的工作方式,那么您可以以某种方式从Xcode服务器获取电子邮件。
Apple论坛的一个成员的建议之后,似乎可以使用 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>

mail.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

您现在将收到此类电子邮件: enter image description here enter image description here 如果有人知道如何添加实际的失败原因或错误,那就太好了。这里有一个我们可以使用的变量列表:这里,我认为它可能涉及查看实际的构建路径。

太棒了,Darren!感谢你做了研究并分享给大家!我希望苹果公司能够更加关注他们的开发工具 :) - Eugene Gordin

2
您的过程完全正确,但只有一个例外。正如您所指出并记录所说,权限存在问题。
如果通过rpm -qV postfixpostfix check共享完整日志以深入了解问题将会很好,但您已经有一些日志表明Xcode没有权限。
此外,您可以使用电子邮件机器人来找出“在Xcode报告导航器中管理机器人”的方法。这里是苹果文档
我认为这将起作用来设置权限:
sudo mkdir -p /Library/Server/Mail/Data/Spool
sudo /usr/sbin/postfix set-permissions
sudo /usr/sbin/postfix start

在运行此命令以清除帖子属性之后,再进行双重检查。
$ 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

重新启动Postfix:
sudo /etc/init.d/postfix start

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

enter image description here


最终编辑:
我的第一个和Edit1的回答对于PO无效。
一些旧的线程表明可能存在不同MacOS版本的错误。这似乎是关于邮政的Big Sur问题。 Thread1 Thread2

不客气。我找到了这个并编辑了我的答案: https://unix.stackexchange.com/questions/471821/how-to-fix-postfix-set-permissions-without-user-named-root - zeytin
1
我认为这可能与Big Sur有关。我发现了这个https://discussions.apple.com/thread/7933518来解决“操作不允许”的问题。我已经禁用了SIP,但现在我得到了错误“chown:/usr/libexec/postfix:只读文件系统”,即使我尝试手动更改“post drop”文件的权限也是如此。 - Darren
1
Big Sur不允许修改根文件系统。我已经按照步骤进行了挂载 https://twitter.com/EBADTWEET/status/1275454103900971012,但在运行“set-permissions”时仍然会出现“操作不允许”的错误。 - Darren
我认为这是Big Sur增加的安全性而不是一个错误。我猜postfix需要一种不同的处理权限的方式。 - Darren
1
没错,我会遵循这个问题,希望你能找到精确而简短的解决方案。 - zeytin
显示剩余5条评论

1
我对Xcode不是很熟悉,但你所描述的问题显然似乎是Xcode应用程序和您的Postfix SMTP服务器之间的通信问题。 我建议尝试以下操作:
1.获取Xcode日志。 - 我在下面找到的帖子中发现可以通过以下方式完成:(a)使用Console.app,(b)通过Terminal.app启动Xcode,或(c)检查诊断报告 - https://dev59.com/lZ_ha4cB1Zd3GeqPuCQA#46674772 2.获取Postfix日志。 - 同样,这些日志可以在Console.app中找到,因为它们应该由ASL(即macOS的syslog)创建。 - 此外,您可以按照Postfix网站上的文档指定自己的日志文件:http://www.postfix.org/MAILLOG_README.html 希望通过这样做,您能够看到您配置的邮件更新是否已从Xcode传输并到达您的Postfix服务器。

谢谢你的帮助。我已经成功找到了日志,看起来可能是权限问题。我已经将日志附加在我的问题上方。谢谢。 - Darren

0

Xcode Server已被弃用,最好转移到Jenkins。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接