Search code examples
jenkinscharacter-encodingruby-2.3

Can't resolve incompatible character encoding in Jenkins


I am attempting to run a Cucumber (Ruby 2.3) Test Suite from Jenkins that tests whether or not 2-4 byte UTF-8 characters are valid names for groups.

I have tried a number of solutions and have been searching for days attempting to find an issue relevant to mine.

The error that has been haunting me is:

incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError)

Which refers to a line where I am attempting to send an ssh command to the CLI on the machine I am creating the group on:

$mymachine.cli_ssh.exec!("config group create --name='#{group_name}'")

Where within the exec!() command exists:

command.force_encoding("UTF-8")

The error only occurs when I am sending 2-4 byte UTF-8 characters, such that:

Group 'abcd' does not cause the error and Group 'ЯЯЯ' does cause the error

The problem:

Running this script on my local Ubuntu machine works perfectly fine (Ruby 2.2.1), as well as other machines in my area. (which is why I do not think it is necessary to provide more code than is given). I know there was a change in encoding to UTF-8 with the jump to Ruby 2.0 but both machines are past that, so I don't think that is the issue.

I have already tried establishing system locales on the Jenkins machine as en_US.UTF-8 both as locale system variables and within the /.bashrc file. No where have I seen an encoding variable set to ASCII-8BIT.

I have also tried exporting the system locales from the Jenkins shell prior to the script's execution.

I am in need of some answer, or some direction that can help me resolve this issue.


Solution

  • The issue was resolved by updating all Ruby gems on the Jenkins system. It is likely that certain gems were out of date even though they were technically compatible with the version of Ruby the Jenkins machine was running, and therefor, there could have existed Ruby code that was non-UTF8.

    If you run into this issue in the future, I would recommend ensuring that all gem and ruby versions are consistent between your Jenkins machine and the working machine.