docker - Jenkins SSH 管道步骤 - 需要一个终端来读取密码

最近我一直在摆弄 Docker/Jenkins 以了解更多有关 CI/CD 工作流的信息。我的目标是拥有一个从 github 获取推送、构建代码并将 JAR 文件发布到远程服务器以进行进一步部署的过程。

我一直在使用 Jenkins SSH Pipeline Steps Plugin这让我可以通过 SSH 连接到我的远程服务器以执行命令。

这是部署阶段,涉及我要执行的命令:

stage("Deploying") {
            steps {
                script {
                    withCredentials([sshUserPrivateKey(credentialsId: 'e48b15ad-0f5e-4f07-8706-635c5250fa29', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'jenkins')]) {
                      remote.user = jenkins
                      remote.identityFile = identity

                      sshCommand remote: remote, command: 'cd Winston-Bot/; sudo ./kill_winston.sh'
                      sshCommand remote: remote, command: 'rm Winston-Bot/*.jar', failOnError:'false'
                      sshCommand remote: remote, command: 'rm -rf Winston-Bot/src', failOnError:'false'
                      sshPut remote: remote, from: "target/Winston-Bot-${VERSION}-jar-with-dependencies.jar", into: 'Winston-Bot/'
                      sshPut remote: remote, from: "src", into: 'Winston-Bot/'
                      sshCommand remote: remote, command: "echo ${VERSION} > Winston-Bot/version.txt"
                    }
                }
            }
        }

当执行cd Winston-Bot/; sudo ./kill_winston.sh 我收到以下错误:

Executing command on ****[51.159.152.230]: cd Winston-Bot/; sudo ./kill_winston.sh sudo: false

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
Failed command ****#15 with status 1: cd Winston-Bot/; sudo ./kill_winston.sh

我已经使用以下代码将 jenkins 用户组添加到 etc/sudoers:

jenkins ALL=(ALL) NOPASSWD: /var/lib/jenkins/Winston-Bot/.kill_winston.sh

当通过终端以用户 jenkins 身份登录我的远程服务器并且不需要密码时,脚本执行得非常好。谁能帮我解决这个问题?

最佳答案

我不确定它是否适合您,但我在 ma​​cOS Big Sur 上遇到了完全相同的问题。无论我如何使用 sudo visudo 编辑 sudoers 文件,它都无法正常工作。

当我创建并编辑正确的文件后,它立即开始工作:sudo visudo -f/etc/sudoers.d/jenkins

jenkins ALL=(ALL) NOPASSWD: ALL

我的想法来自 this comment和 this answer .

https://stackoverflow.com/questions/67534354/

相关文章:

python - 如何减少 PyQt5 QGridLayout 中两个小部件之间的空间?

javascript - 有什么办法可以缩短这段代码吗?

clojure - 如何在 clojure 中生成随机字母数字字符串?

python - 检查是否存在与列表中的字符串匹配的子字符串

sql - 如何计算运行平均值

python - 为什么我没有从使用编码数据库中得到 SQL 查询的结果?

java - 如果读取字节数为 0,是否有任何理由继续读取 InputStream?

python - 无法使用 pytesseract.image_to_string 从图像中读取文本

r - 为什么 geom_smooth 不绘图? (唯一值不足错误)

amazon-web-services - 为什么 X-Forwarded-Proto 在 Elas