Issue Description:
I’m encountering an error in my GitLab CI/CD pipeline, specifically during the execution of a job. The error message is:
Cannot perform an interactive login from a non TTY device
my gitlab ci/cd:
deploy-job:
stage: deploy
image:
name: docker:24.0.6
services:
- docker:24.0.6-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- echo $DOCKER_USER
- echo "$DOCKER_PASS" > ./my_psw.txt
- cat ./my_psw.txt
script:
- mkdir -p /root/.docker
- cat ./my_psw.txt | docker login --username genadigeno --password-stdin
- docker build --tag genadigeno/emergency-service:$IMAGE_TAG .
- docker push genadigeno/emergency-service:$IMAGE_TAG
- echo "Application successfully deployed."
after_script:
- echo "" > ./my_psw.txt
- cat ./my_psw.txt
- docker logout
except:
- main
I have tried to login via docker login -u $DOCKER_USER -p $DOCKER_PASS but same error.
actually when I run echo $DOCKER_USER or $DOCKER_PASS does not printed anything…
>Solution :
Cannot perform an interactive login from a non TTY device error occurs when you use –password-stdin but no password is supplied.
Looks like DOCKER_USER and DOCKER_PASS variables are setup at project/group level variables. And they are marked as "protected" variables. Hence they can be used only on protected branches(for example main) or protected tag.
Your pipeline runs on a branch other than "main".
except:
- main
So on a non protected branch a protected variable value will be empty and hence the error from docker
Solution:
If you want to use these variables on branches other than main then do the following
Under Setting->CI/CD settings->CI/CD Variables "edit" the variable DOCKER_USER and DOCKER_PASS and uncheck the Flag "Protect variable" and save.