在gitlab-ci.yml中使用sudo时如何避免密码? [英] How to avoid password when using sudo in gitlab-ci.yml?

查看:317
本文介绍了在gitlab-ci.yml中使用sudo时如何避免密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个专用的docker仓库,用于存储构建映像。
我确实复制了我的注册表证书并更新了/ etc / hosts文件以从本地计算机上对注册表进行身份验证。

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.

我可以使用<$ c登录到注册表$ c>'sudo docker login -u xxx -p xxx Registry-name:port'

但是当我尝试从gitlab-ci阶段,它失败并出现以下错误:

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


sudo:不存在tty且未指定AskPass程序。 p>

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}"

我还尝试在/ etc / sudoers底部添加此gitlab-runner ALL =(ALL)NOPASSWD:ALL 文件,但是没有运气
我要去哪里了?

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?

推荐答案

据此

According to this Source you can use

ssh -t remotehost "sudo ./binary"

-t分配一个伪tty。

The -t allocates a pseudo-tty.

或在您的示例中:

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

这篇关于在gitlab-ci.yml中使用sudo时如何避免密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆