【问题标题】:Jenkins SSH Pipeline Steps - A terminal is required to read the passwordJenkins SSH 管道步骤 - 需要终端才能读取密码
【发布时间】:2021-05-14 12:28:37
【问题描述】:

最近我一直在研究 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 身份登录到我的远程服务器时,脚本执行得非常好,并且不需要密码。谁能帮我解决这个问题?

【问题讨论】:

    标签: docker jenkins deployment jar jenkins-pipeline


    【解决方案1】:

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

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

    jenkins ALL=(ALL) NOPASSWD: ALL
    

    我的想法来自this commentthis answer

    【讨论】:

      猜你喜欢
      • 2021-10-10
      • 2016-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 1970-01-01
      • 2013-03-26
      • 2010-11-05
      相关资源
      最近更新 更多