How to escape $ in Ubuntu build worker?

justin.yoojh's Avatar

justin.yoojh

16 Jun, 2018 11:06 AM

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?

  1. Support Staff 1 Posted by wasapl on 16 Jun, 2018 07:30 PM

    wasapl's Avatar

    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 ;))

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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