How to avoid password when using sudo in gitlab-ci.yml?

谁说胖子不能爱 提交于 2020-01-16 10:03:11

问题


I have a private docker repository where i store my build images. I did copy my registry certificates and updated my /etc/hosts file to authenticate registry from my local machine.

I could login to registry with 'sudo docker login -u xxx -p xxx registry-name:port'

But when i try same docker login command from gitlab-ci stage, it is failing with this error:

sudo: no tty present and no askpass program specified.

This is how i'm trying to achieve this.

ssh manohara@${DEPLOY_SERVER_IP} "sudo docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}"

I also tried adding this gitlab-runner ALL=(ALL) NOPASSWD: ALL at the bottom of /etc/sudoers file, but no luck Where am i going wrong?


回答1:


According to this Source you can use

ssh -t remotehost "sudo ./binary"

The -t allocates a pseudo-tty.

Or in your example:

ssh -t manohara@${DEPLOY_SERVER_IP} "sudo docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}"


来源:https://stackoverflow.com/questions/49537149/how-to-avoid-password-when-using-sudo-in-gitlab-ci-yml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!