Bitbucket Pipelines docker login: "Error: Cannot perform an interactive login from a non TTY device"
A Pipelines step has no terminal. When docker login is missing the user name or the password, it would ask for it at a prompt, and with nobody to answer, it stops with this:
Error: Cannot perform an interactive login from a non TTY device
What Docker does
The Docker CLI pull request login: handle non-tty scenario consistently (in Docker 27.2.1) lists the cases for a login without a terminal:
- User name and password both given: the login works.
- Neither given, or only the user name: the error above.
- A password (
--passwordor--password-stdin) and no user name:docker loginnow returns an error instead of hanging, which is how older clients behaved.
So in a pipeline, the error nearly always means a variable in -u "$USER" or -p "$PASS" expanded to nothing. An empty password counts as no password.
While you track down the empty variable: Pipeline Inbox for Bitbucket Pipelines, a plugin for JetBrains IDEs, lists the pipelines of every Bitbucket Cloud repository you have in a tool window of the IDE, with the failed step and the command it stopped at.
The command
Docker's docker login page says to use --password-stdin to log in non-interactively, which also keeps the password out of the shell history and the log files. In the YAML, with the services Docker needs:
pipelines:
default:
- step:
services:
- docker
script:
- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
- docker pull your-org/your-image:tag
Without a server name, docker login goes to Docker Hub. For another registry, add its name at the end: docker login --username "$REGISTRY_USER" --password-stdin registry.example.com (the page's example for a self-hosted registry). Quote the variables: an unquoted empty one disappears from the command and moves the arguments up.
Name the empty variable
Put a check before the login, so the step says which variable is missing instead of printing the TTY message:
script:
- test -n "$DOCKER_USERNAME" || { echo "DOCKER_USERNAME is empty"; exit 1; }
- test -n "$DOCKER_PASSWORD" || { echo "DOCKER_PASSWORD is empty"; exit 1; }
- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
A secured variable is masked in the log, so echo shows nothing useful. test -n does not print it, and echo "DOCKER_PASSWORD has ${#DOCKER_PASSWORD} characters" shows whether it arrived.
Why the variable is empty
The causes are the ones on A variable is empty. The two that show up with docker login most:
- The variable is a deployment variable, and the step does not name that environment with
deployment:. It then reaches no other step. - The name in the YAML differs from the name in the settings by a letter or by case.
Another reason to look at the whole log: if an earlier command that fills the variable failed (a login helper that was not installed, say), the variable stays empty and the first visible failure is the login. If it is not the variable, "authorization denied by plugin pipelines" is a different Docker message, covered on its own page.
Bitbucket Pipelines in IntelliJ IDEA
Pipeline Inbox for Bitbucket Pipelines, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the pipelines of all your Bitbucket Cloud repositories in an IDE tool window, with their steps, the failed step and the command it stopped at, and the step's log as Bitbucket writes it. The failed docker login line and its output come first in the step, and the commands before it are marked in the log, so you can see whether the variable was filled earlier. The list, steps and logs are free; running, re-running and stopping pipelines are Pro (US$1.50 a month, with a 30-day trial).
Get it on JetBrains Marketplace
Atlassian, Bitbucket and Bitbucket Pipelines are trademarks of Atlassian; Docker is a trademark of Docker, Inc.; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian, Docker or JetBrains.
More: Test results not showing · A variable is empty · "Host key verification failed" (SSH) · "Cannot connect to the Docker daemon" · "authorization denied by plugin pipelines" (Docker) · "Container 'docker' exceeded memory limit." · Pipelines did not run after a push · "Container 'Build' exceeded memory limit." · "Exceeded build time limit of 120 minutes" · The cache is not used · "unexpected system error" · "command not found" · Submodules not cloned · "We couldn't clone the repository" · "No online runner available" · "No space left on device" · "Step exceeded processing limits" · The artifact is missing in the next step · The build passed before and fails now · Build setup takes too long · "You've run out of build minutes" · "Permission denied to update branch" · "You have reached your pull rate limit" (Docker Hub) · "There is an error in your bitbucket-pipelines.yml" · "This pipeline was paused" (deployments) · "Connection refused" to a service (MySQL, PostgreSQL, Redis) · "Container 'build' failed to pull image" · The scheduled pipeline did not run · Git commands that fail in a shallow clone (origin/main, git describe) · Git LFS files that arrive as pointers, and LFS pushes from a step · A step skipped by condition: changesets (includePaths) · Parallel steps that keep running after one fails (fail-fast) · Bitbucket Pipelines plugins for IntelliJ IDEA, compared · "Not authorized to perform sts:AssumeRoleWithWebIdentity" (OIDC to AWS) · "AADSTS70021" OIDC to Azure (Entra ID) · "Permission 'iam.serviceAccounts.getAccessToken' denied" OIDC to Google Cloud · 日本語