Why is echo not working in Doppler but printenv works fine?

729 Views Asked by At

I have the following command...

doppler run -- printenv TEST_PASSWORD

I see the value for TEST_PASSWORD, however, when I run the following...

doppler run -- echo $TEST_PASSWORD

Nothing is returned. How do I echo out existing secrets to debug something?

2

There are 2 best solutions below

0
stonecharioteer On

I ran into this same issue and this is what I understood from mucking around with the environment. Doppler injects the secrets when the command is executed. That means that the containing shell process does not have access to the command. printenv is a command that uses the argument TEST_PASSWORD as a key within its own runtime. It doesn't depend on the underlying shell to resolve TEST_PASSWORD to the value you've mapped in doppler. However, when you use echo $TEST_PASSWORD, this won't have any value (or it will have the value that your encompassing shell may have already had, if it did), since doppler hasn't yet injected the value.

Try the same thing but instead, put your echo command(s) into a shell script and execute it with doppler run -- bash script.sh, it will work now because the encompassing shell then executes this command and doppler injects the values therein.

0
pa4080 On

It is a strange behavior, but according to the documentation we need to use the --command option in such cases:

doppler run --command 'redis-cli -u "$REDIS_URL"'

Another way is to use the command option of some of the available shells:

doppler run -- sh -c 'redis-cli -u "$REDIS_URL"'