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.

(1) Open the ~/Library/LaunchAgents/gitlab-runner.plist file.

(2) 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


Authored Books

  • URLをコピーしました!
  • URLをコピーしました!


Akira Hayashi (林 晃)のアバター Akira Hayashi (林 晃) Representative(代表), Software Engineer(ソフトウェアエンジニア)

アールケー開発代表。Appleプラットフォーム向けの開発を専門としているソフトウェアエンジニア。ソフトウェアの受託開発、技術書執筆、技術指導・セミナー講師。note, Medium, LinkedIn
Representative of RK Kaihatsu. Software Engineer Specializing in Development for the Apple Platform. Specializing in contract software development, technical writing, and serving as a tech workshop lecturer. note, Medium, LinkedIn