How to resolve xcpretty locale error launched from GitLab CI

When executing XCTest through GitLab CI, you may encounter the following error.

/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 will guide you through resolving this issue.


Error Cause

This error occurs when xcpretty fails to process a string from the xcodebuild log output, causing xcpretty to crash and preventing xcodebuild from outputting the log.


You can address this issue by properly setting the locale for gitlab-runner. Follow the steps below.

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" "">
<plist version="1.0">

<!-- omission -->

Restart your machine, or you can relaunch the gitlab-runner as show below.
gitlab-runner stop
gitlab-runner start
Let's share this post !