When running XCTest using GitLab’s CI, the job may fail with the following error output.
/Library/Ruby/Gems/2.6.0/gems/xcpretty-0.3.0/lib/xcpretty/parser.rb:434:in `===': invalid byte sequence in US-ASCII (ArgumentError) from /Library/Ruby/Gems/2.6.0/gems/xcpretty-0.3.0/lib/xcpretty/parser.rb:434:in `update_test_state' from /Library/Ruby/Gems/2.6.0/gems/xcpretty-0.3.0/lib/xcpretty/parser.rb:307:in `parse' from /Library/Ruby/Gems/2.6.0/gems/xcpretty-0.3.0/lib/xcpretty/formatters/formatter.rb:88:in `pretty_format' from /Library/Ruby/Gems/2.6.0/gems/xcpretty-0.3.0/lib/xcpretty/printer.rb:19:in `pretty_print' from /Library/Ruby/Gems/2.6.0/gems/xcpretty-0.3.0/bin/xcpretty:84:in `block in <top (required)>' from /Library/Ruby/Gems/2.6.0/gems/xcpretty-0.3.0/bin/xcpretty:83:in `each_line' from /Library/Ruby/Gems/2.6.0/gems/xcpretty-0.3.0/bin/xcpretty:83:in `<top (required)>' from /usr/local/bin/xcpretty:23:in `load' from /usr/local/bin/xcpretty:23:in `<main>' 2022-06-28 19:15:17.149 xcodebuild[28965:188047] NSFileHandle couldn't write. Exception: *** -[_NSStdIOFileHandle writeData:]: Broken pipe
This article explains how to solve this problem.
This error is caused by a string in the log output by
xcpretty cannot process,
xcpretty crashed and
xcodebuild to be unable to output the log.
You can solve this problem by correctly setting the locale of
gitlab-runner. Do as follows.
Open the ~/Library/LaunchAgents/gitlab-runner.plist file.
Add the EnvironmentVariables as follows.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <!-- 省略 --> <key>EnvironmentVariables</key> <dict> <key>LC_ALL</key> <string>en_US.UTF-8</string> </dict> </dict>
Reboot your machine, or relaunch gitlab-runner as follows.
gitlab-runner stop gitlab-runner start