Environment variables don't seem to work well with spaces in 2.0

I have not tried with v1.0 config.

Anyway, the specific command I was running is

docker login -u $DOCKER_USER -p $DOCKER_PASSWORD

This works well with no spaces in the password, but fails with spaces.

1 Like

Have you tried quotes?

docker login -u '$DOCKER_USER' -p '$DOCKER_PASSWORD'

Remember that in shell commands, variables are just interpolated, so if you have --switch my variable then it will assign “my” to --switch and not know what to do with the second part. Quotes stop that happening.

It’s worth noting also that if you have quotes in your variables, they need to be escaped in order for the shell not to misinterpret them.

1 Like

Thanks @halfer, I did try that but it was then passing the string '$DOCKER_USER' for example to docker login rather than the environment variable. But once I figured out it was the spaces I just left it as that, maybe not ideal but it works. :wink:

I just left it here because it felt like a bug - docker login -u $DOCKER_USER -p $DOCKER_PASSWORD will work in bash but not as a CircleCI run command. I think this could potentially cause others to lose time as the behaviour could be a bit random, and the error unlikely to directly point to the issue.

1 Like

I can’t remember the specifics here, but maybe single and double quotes are treated differently in terms of whether variables interpolate? I know they are in PHP, and I forget if shells are different or the same! Try double quotes then, to see if that fixes it.