circleci-cli
circleci-cli copied to clipboard
Cannot pass JSON strings as environment variables to `circleci local execute`
- [x] I have read Contribution Guidelines.
- [x] I have checked for similar issues and haven't found anything relevant.
- [x] This is not a security issue (which should be reported here: https://circleci.com/security/)
Do you want to request a feature or report a bug?
Bug.
What is the current behavior?
I'm trying to use a base image from the Google Container Registry. Authentication works if I set the JSON key belonging to the Service Account as a protected environment variable in the CircleCI interface, but I'm getting an error when trying to pass it to the local agent as well:
Error: invalid argument <JSON> for "-e, --env" flag: parse error on line <LINE>, column <COLUMN>: bare " in non-quoted-field
Can you provide an example?
All these commands fail with the same error:
circleci local execute --env TEST="{\"foo\":\"bar\"}"circleci local execute --env "TEST={\"foo\":\"bar\"}"circleci local execute --env 'TEST={"foo":"bar"}'circleci local execute --env 'TEST={\"foo\":\"bar\"}'
What is the expected behavior?
The environment variable value should be the JSON string.
Which version of the CLI and OS are you using? Did this work in previous versions?
Versions below. I don't know if this worked in a previous version.
❯ circleci version
0.1.8945+e08af42 (release)
❯ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.1
BuildVersion: 18B75
❯ circleci diagnostic
---
CircleCI CLI Diagnostics
---
Debugger mode: false
Config found: /Users/<USER>/.circleci/cli.yml
API host: https://circleci.com
API endpoint: graphql-unstable
OK, got a token.
Trying an introspection query on API...
Ok.
Hello, <NAME>.
Come on guys, can this issue at least be acknowledged or something? Not necessarily asking for a resolution, but at least something to know you've seen it.
@victorstanciu To be clear, it's the GCP command providing this error? Or the CLI itself? I'm unable to replicate this myself at the moment, and want to try and focus in on what is throwing the error in question.
@gmemstr it's the circleci executable, running on my Mac. It doesn't even get to the GCP commands:

Interesting. I'm wondering if this is some strange behaviour macOS is exhibiting with quotes. One final bit of information, what terminal application are you using? Passing this along internally and we want to try and get as close to your setup as possible.
It happens in both iTerm2 and the default Terminal.app. I'm happy to provide any other information you think might help.
@gmemstr Hmm, I think you're onto something. I tested it now on a Windows machine with WSL2, and I don't get the error.
Would you mind telling us what shell you are using on macOS?
On Mon, Jan 18, 2021 at 3:41 PM Victor Stanciu [email protected] wrote:
@gmemstr https://github.com/gmemstr Hmm, I think you're onto something. I tested it now on a Windows machine with WSL2, and I don't get the error.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CircleCI-Public/circleci-cli/issues/450#issuecomment-762326744, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAALNYQ3IAUYYDE7PKXLBPDS2RJCBANCNFSM4PUGHBOQ .
Happens in both Zsh and Bash on the Mac.
Experiencing this issue as well
A potential solution I found is to base64 encode the json and then decode where ever you are reading it from. I know this might not work for some use cases, but it's the only I option I could use.