Here is hot you can Fix Cloud Build / Cloud Run Error: argument --set-env-vars: Bad syntax for dict arg
While deploying a service to Google Cloud Run through Cloud Build, I ran into this error:
ERROR: (gcloud.run.deploy) argument --set-env-vars:
Bad syntax for dict arg: [http://localhost:3000].
At first glance, the deployment config looked fine. I was passing multiple allowed origins like this:
ALLOWED_ORIGINS=https://example-app.run.app,http://localhost:3000,http://localhost:3001
✅ What caused the error?
Cloud Run’s --set-env-vars flag splits values using commas.
Since the environment variable itself contained commas, Cloud Run thought I was trying to define new variables:
https://example-app.run.apphttp://localhost:3000http://localhost:3001
So it broke parsing and threw the error.
The first try: wrap the value in quotes
Just add quotes around the value:
ALLOWED_ORIGINS="https://example-app.run.app,http://localhost:3000,http://localhost:3001",
Nothing changes — Couple of dev suggested this but this is not a woking solution.
✅ Working fix: escape commas using ^@^
Instead of quoting (which surprisingly did not work for Cloud Build), the fix was to escape the commas using a safe placeholder (^@^), like this:
ALLOWED_ORIGINS=^@@^https://example.run.app,http://localhost:3000,http://localhost:3001
🎉 Result
✅ Cloud Run accepts the variable
✅ No syntax error
✅ Your app still gets a proper list of origins
Comments
Post a Comment