How to escape $ in Ubuntu build worker?
Hi, Team.
I'm using Ubuntu as the build worker image. In the CI/CD pipeline, I need to provide a sensitive information for login to Docker using the following command:
docker login -u $docker_username -p $docker_password
The $docker_password value is "Pa$$W0rd", for example (without double quotations). However, if I run the command within the build script, it returns a different value like "Pa1953W0rd", which the digits vary every time.
I tried to wrap $docker_password with " (double quote) or ' (single quote) but none of both worked. I also changed the value to "Pa\$\$W0rd", but it still returns "Pa1234W0rd".
What else can I do for my password escaping?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Wasa Pleshakov on 16 Jun, 2018 07:30 PM
Justin,
https://docs.docker.com/engine/reference/commandline/login/
describes several ways to provide a password to docker command.
In part "Provide a password using STDIN" there is a quite simple example:
$ cat ~/my_password.txt | docker login --username foo --password-stdin But If you don't want to write password to file and you store it in variable $docker_password you may rewrite this example like this:
docker login --username foo --password-stdin <<< "$docker_password"
There is "Credentials store" and "Credential helper protocol" parts of https://docs.docker.com/engine/reference/commandline/login/ also worth to read,
But frankly, do not use dollar sign in bash strings. This will save you a lot of time ;))
Ilya Finkelshteyn closed this discussion on 31 Aug, 2018 07:53 PM.