From c3ac2053b5be4f54bc155d3a345f8cabc7dbe6cb Mon Sep 17 00:00:00 2001 From: Charles Care Date: Thu, 5 Dec 2019 15:42:41 +0000 Subject: [PATCH] Force logs encoding --- lib/pipeline/build/container_build.rb | 2 +- lib/pipeline/util/external_command.rb | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/pipeline/build/container_build.rb b/lib/pipeline/build/container_build.rb index 6882849..bd2d57d 100644 --- a/lib/pipeline/build/container_build.rb +++ b/lib/pipeline/build/container_build.rb @@ -32,7 +32,7 @@ module Pipeline::Build image: image_name, image_tag: image_tag, git_tag: build_tag, - logs: img.logs.inspect.force_encoding("ISO-8859-1").encode("UTF-8") + logs: img.logs.inspect } end diff --git a/lib/pipeline/util/external_command.rb b/lib/pipeline/util/external_command.rb index 7677bf1..0fb7de8 100644 --- a/lib/pipeline/util/external_command.rb +++ b/lib/pipeline/util/external_command.rb @@ -56,13 +56,22 @@ module Pipeline::Util { cmd: cmd_string, success: success?, - stdout: stdout, - stderr: stderr + stdout: fix_encoding(stdout), + stderr: fix_encoding(stderr) } end private + def fix_encoding(text) + return nil if text.nil + text.force_encoding("ISO-8859-1").encode("UTF-8") + rescue => e + puts e.message + puts e.backtrace + "--- failed to encode as UTF-8: #{e.message} ---" + end + def invoke_process c = cmd captured_stdout = []