Export LANG via config.yml - rspec ArgumentError: invalid byte sequence in US-ASCII

rspec

#1

If I attempt the following in the config.yml

  • run:
    name: Export Lang
    command: export LANG=C.UTF-8

Followed by
- run:
name: Ruby lang
command: ruby -e ‘puts Encoding.default_external’

The result from the above is
US-ASCII

If I set Env. var via the GUI: https://circleci.com/gh/foodpony/donutz/edit#env-vars
Name: LANG Value: C.UTF-8

The result is
UTF-8

Will export LANG eventually work from the config.yml?

Issue originally stemmed from ‘bundle exec rspec’ throwing
ArgumentError: invalid byte sequence in US-ASCII


#2

It already works but sourcing files or changing the shell only impacts the command from which it’s being run. Use this instead:

- run:
    name: Ruby lang
    command: |
      export LANG=C.UTF-8
      ruby -e 'puts Encoding.default_external'

#3

Ah that makes sense, works a charm!

Thanks for the quick reply!


#4

#5

If you’re going to use rspec in more than one step, I suggest using a higher level environment: specifier. For instance:

version: 2

jobs:
  build:
    docker:
      - image: ruby:2.4.0
    workDir: /my-project
    environment:
      - LANG: C.UTF-8
    parallelism: 2
    steps:
      - checkout

      - run:
          name: Ruby lang
          command: |
            ruby -e 'puts Encoding.default_external'

      - run:
          name: Ruby lang
          command: |
            ruby -e 'puts Encoding.default_external'

This example puts the variable at the job level, you could also specify it at the image level, like so:

version: 2

jobs:
  build:
    docker:
      - image: ruby:2.4.0
        environment:
          - LANG: C.UTF-8
    workDir: /my-project
    parallelism: 2
    steps:
      - checkout

      - run:
          name: Ruby lang
          command: |
            ruby -e 'puts Encoding.default_external'

      - run:
          name: Ruby lang
          command: |
            export LANG=C.UTF-8
            ruby -e 'puts Encoding.default_external'

I recommend either approach if you want to set an environment variable to a static value, like C.UTF-8 in this case.