Trouble setting environment variables via the command line

I’m attempting to set GIT_SHA and GIT_AUTHOR runtime environment variables, but I get the following error:

fly deploy --remote-only \
  -e GIT_SHA=$(git rev-parse HEAD) \
  -e GIT_AUTHOR=$(git log -1 --format='%aN <%aE>' | xargs)

Error: accepts at most 1 arg(s), received 2

If I only use a single -e flag, the deploy goes through, but it appears to be clobbering my other environment variables set via [env] in fly.toml. I throw an error in my config/runtime.exs file if required variables are not set, and I’m observing those errors:

==> Release command detected: /app/bin/migrate

--> This release will not be available until the release command succeeds.
	 Starting instance
	 Unpacking image
	 Preparing kernel init


	 Configuring firecracker
	 Starting virtual machine
	 Starting init (commit: e21acb3)...
	 Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
	 no label, UUID=dddff522-c4d6-4ca1-b794-141e32b1b853
	 Preparing to run: `/app/bin/migrate` as nobody
	 2022/06/18 23:51:10 listening on [fdaa:0:61d4:a7b:775a:1bc9:f554:2]:22 (DNS: [fdaa::3]:53)
	 ERROR! Config provider Config.Reader failed with:
	 ** (RuntimeError) environment variable APP_HOST is missing.
	     /app/releases/0.1.0/runtime.exs:26: MightyConfig.get_env!/2

No such error occurs when I don’t use -e flags, so this seems to be the culprit.

Related: Git commit sha of current build

Hmm, I’m thinking the value passed to -e might have a space, so it’s being parsed as another arg.

Try putting quotes around $(git log -1 --format='%aN <%aE>' | xargs).

Thanks, that was indeed the problem with GIT_AUTHOR! Now just seeing that [env] is getting clobbered while running my release_command :thinking:

Ah ha! Just found this: Specifying env vars with 'fly deploy -e' wipes out env vars set in fly.toml · Issue #560 · superfly/flyctl · GitHub

Looks like a merge might be imminent :slight_smile: