4

我们的开发团队一直使用 Jenkins 进行 iOS 构建,并在构建(黄色)、成功(绿色)、失败(红色)时使用 Philips Hue 灯通知团队。

现在我们已经转移到Xcode CI 和 Bots,我不知道任何单元测试何时失败。我们甚至不知道构建阶段是否失败。

在 Xcode Bots CI 上,你会得到这个“大屏幕”功能:在 Apple 的“Manage and Monitor Bots from a Web Browser”Docs中,你可以看到它有各种可以点亮色调的状态。

我真的不想破解一些东西并解析 HTML 页面。虽然很有趣,但如果 Apple 更新他们的 HTML 标记,这项工作不会持续很长时间。

当 Xcode 机器人完成集成时,是否会生成一个可解析的文件?

我希望色调显示:
* 蓝色表示分析警告
* 橙色表示构建警告
* 红色表示构建错误
* 黄色表示构建运行

4

3 回答 3

6

我想分享团队的解决方案。我们找到了存储 Bot 结果的地方,我们使用 bash 解析它,并通过 curl 系统调用向 HUE 灯发送消息。我们在构建脚本前后调用方案中的脚本。

我们在以下位置解析机器人的结果 plist:

/Library/Server/Xcode/Data/BotRuns/Latest/output/xcodebuild_result.bundle/Info.plist

在那里你可以找到各种很酷的数据来使用!:

<dict>
    <key>AnalyzerWarningCount</key>
    <integer>0</integer>
    <key>AnalyzerWarningSummaries</key>
    <array/>
    <key>ErrorCount</key>
    <integer>0</integer>
    <key>ErrorSummaries</key>
    <array/>
    <key>LogIdentifier</key>
    <string>705bffcb-7453-49ba-882f-80e1218b59cf</string>
    <key>LogPath</key>
    <string>1_Test/action.xcactivitylog</string>
    <key>Status</key>
    <string>IDEActionResultStatus_Succeeded</string>
    <key>TestFailureSummaries</key>
    <array/>
    <key>TestSummaryIdentifier</key>
    <string>a1554874-4d40-4e94-ae89-a73184ec97a9</string>
    <key>TestSummaryPath</key>
    <string>1_Test/action_TestSummaries.plist</string>
    <key>TestsCount</key>
    <integer>185</integer>
    <key>TestsFailedCount</key>
    <integer>0</integer>
    <key>WarningCount</key>
    <integer>0</integer>
    <key>WarningSummaries</key>
    <array/>
<dict>
  • AnalyzerWarningCount
  • 错误计数
  • 警告计数
  • 测试失败计数

哦,bash,我有时的情人,再来拯救一天。

还要注意使用 Plist Buddy 来解析 Xcode 的 XML 属性列表文件。从 plist 文件中获取信息的首选。

    #!/bin/bash
    #
    #   By Phil
    #
    exec > /tmp/my_log_file.txt 2>&1
    TEST_RESULT_PLIST="/Library/Server/Xcode/Data/BotRuns/Latest/output/xcodebuild_result.bundle/Info.plist"

    hue_light_green=false

    echo "testResultParse_OwlHue"

    #If not bot, return
    if [ "$(whoami)" != "_teamsserver" ]; then
        echo "$(whoami) - Not a bot!";
        exit 1
    fi

    #1 If file not found ERROR
    if [ ! -f $TEST_RESULT_PLIST ]; then
        curl -X PUT -d "{\"on\":true,\"bri\":32,\"effect\":\"none\",\"hue\":150,\"sat\":255,\"alert\":\"lselect\"}" ipaddress/api/testestest/lights/3/state
        echo "Test Result Plist not Found";
        exit 1
    fi

    #2 AnalyzerWarningCount BLUE
    AnalyzerWarningCount=$(/usr/libexec/PlistBuddy -c "Print :AnalyzerWarningCount" "${TEST_RESULT_PLIST}")
    if [ $AnalyzerWarningCount != 0 ]; then
        echo "AnalyzerWarningCount";
        curl -X PUT -d "{\"on\":true,\"bri\":32,\"xy\":[0.16, 0.1],\"hue\":15815,\"sat\":255,\"effect\":\"none\",\"alert\":\"lselect\"}" ipaddress/api/testestest/lights/3/state
    fi

    #3 WarningCount
    WarningCount=$(/usr/libexec/PlistBuddy -c "Print :WarningCount" "${TEST_RESULT_PLIST}")
    if [ $WarningCount != 0 ]; then
        curl -X PUT -d "{\"on\":true,\"bri\":32,\"xy\":[0.58, 0.41],\"hue\":15815,\"sat\":255,\"effect\":\"none\",\"alert\":\"lselect\"}" ipaddress/api/testestest/lights/3/state
        echo "WarningCount";
    fi

    #4 ErrorCount || TestsFailedCount ERROR
    ErrorCount=$(/usr/libexec/PlistBuddy -c "Print :ErrorCount" "${TEST_RESULT_PLIST}")
    if [ $ErrorCount != 0 ]; then
        curl -X PUT -d "{\"on\":true,\"bri\":32,\"effect\":\"none\",\"hue\":150,\"sat\":255,\"alert\":\"lselect\"}" ipaddress/api/testestest/lights/3/state
        echo "ErrorCount";
        exit 1
    fi

    #5 TestsFailedCount ERROR
    ErrorCount=$(/usr/libexec/PlistBuddy -c "Print :ErrorCount" "${TEST_RESULT_PLIST}")
    if [ $TestsFailedCount != 0 ]; then
        curl -X PUT -d "{\"on\":true,\"bri\":32,\"effect\":\"none\",\"hue\":150,\"sat\":255,\"alert\":\"lselect\"}" ipaddress/api/testestest/lights/3/state
        echo "TestsFailedCount";
        exit 1
    fi

    #6 None of the above.  SUCCESS
    if [ "$hue_light_green" = true ] ; then
        echo "SUCCESS";
        curl -X PUT -d "{\"on\":true,\"bri\":32,\"effect\":\"none\",\"hue\":25500,\"sat\":255,\"alert\":\"lselect\"}" ipaddress/api/testestest/lights/3/state
    fi
  • AnalyzerWarningCount蓝色
  • 错误计数红色
  • 警告计数橙色
  • 测试失败计数红色

现在,当我们计算上述任何一项时,我们会看到闪烁的颜色变化。例如,下面的代码会从我们的色调中产生明亮的蓝色: 在此处输入图像描述

于 2014-03-15T04:34:55.857 回答
4

对于在此处查看这些答案的任何人来说,buildService.log文件的抓取是不必要的(实际上甚至不会工作,因为相对于运行触发器何时创建日志的鸡/蛋问题)。尝试env在 Trigger Script 中运行命令,您会看到 Xcode 实际上使用测试结果设置环境变量,其中一些比较值得注意的是:

XCS_BOT_NAME=My New Bot
XCS_WARNING_CHANGE=0
XCS_INTEGRATION_RESULT=succeeded
XCS_TEST_FAILURE_COUNT=0
XCS_TEST_FAILURE_CHANGE=0
XCS_ERROR_COUNT=0
XCS_ANALYZER_WARNING_COUNT=0
XCS_TESTS_CHANGE=0
XPC_SERVICE_NAME=0
XCS_ERROR_CHANGE=0
XCS_WARNING_COUNT=0
XCS_TESTS_COUNT=3
XCS_INTEGRATION_NUMBER=1
于 2014-12-10T22:23:04.370 回答
4

OS X Server 4.0 的结果路径似乎是:

/Library/Developer/XcodeServer/IntegrationAssets/Your_Bot/

  • 存档.xcarchive.zip
  • 构建日志
  • 构建服务日志
  • Your_Bot.ipa
  • 源控制日志
  • xcodebuild_result.bundle.zip

xcodebuild_result.bundle 现在是一个 zip 文件,我从 buildService.log 解析构建结果:

Build results summary: {
analyzerWarningChange = 14;
analyzerWarningCount = 14;
errorChange = 0;
errorCount = 0;
improvedPerfTestCount = 0;
regressedPerfTestCount = 0;
testFailureChange = 0;
testFailureCount = 0;
testsChange = 0;
testsCount = 0;
warningChange = 20;
warningCount = 20;
}
于 2014-11-19T09:48:57.997 回答