sshPut 在 Jenkins PL 中失败并显示 AuthFail

问题描述 投票:0回答:1

尝试通过 ssh 部署到远程主机。我已经使用 bash 命令通过相同的 jenkins 管道测试了 sshkey 并且它有效。 echo 也能正确打印 var 值。所以不知道为什么身份验证失败。

stage('Deploy to Host') {
        steps {
            sshagent(credentials: ['dev-host-ssh-key']) {
                script {
                    def remote = [:]
                    remote.name = 'remote-host'
                    remote.host = "$HOST"
                    remote.user = "$APP_USER"
                    remote.allowAnyHosts = true
                    echo "HOST: ${remote.host}"
                    echo "BASE_DIR: ${env.BASE_DIR}"
    echo "APP_USER: ${remote.user}"

                    try {
        sshPut remote: remote, from: 'scripts/', into: "$BASE_DIR/$APP_USER/"
    } catch (Exception e) {
        echo "Error during sshPut: ${e.message}"
    }

try/catch 捕获错误消息。请交流,因为我别无选择,只能将长日志添加为 html 代码。

17:00:24  Identity added: /var/org/jenkins/b12adfb/workspace/3536173/some-dir@tmp/private_key_94848422121.key 
17:00:24  [ssh-agent] Started.
17:00:24  [Pipeline] {
17:00:24  [Pipeline] script
17:00:24  [Pipeline] {
17:00:24  [Pipeline] echo
17:00:24  HOST: correct_host_echoed
17:00:24  [Pipeline] echo
17:00:24  BASE_DIR: correct_dir_echoed
17:00:24  [Pipeline] echo
17:00:24  APP_USER: correct_user_echoed
17:00:24  [Pipeline] sshPut
17:00:25  [Pipeline] echo
17:00:25  Error during sshPut: Auth fail
17:00:25  [Pipeline] sshCommand
17:00:25  [Pipeline] }
17:00:25  [Pipeline] // script
17:00:25  [Pipeline] }
17:00:25  $ ssh-agent -k
17:00:25  unset SSH_AUTH_SOCK;
17:00:25  unset SSH_AGENT_PID;
17:00:25  echo Agent pid 1471169 killed;
17:00:25  [ssh-agent] Stopped.
17:00:25  [Pipeline] // sshagent
17:00:25  [Pipeline] }
17:00:25  [Pipeline] // stage
17:00:25  [Pipeline] stage
17:00:25  [Pipeline] { (Declarative: Post Actions)
17:00:25  [Pipeline] cleanWs
17:00:25  [WS-CLEANUP] Deleting project workspace...
17:00:25  [WS-CLEANUP] Deferred wipeout is used...
17:00:25  [WS-CLEANUP] done
17:00:25  [Pipeline] End of Pipeline
17:00:25  Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to Podman-p1139181
17:00:25        at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784)
17:00:25        at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
17:00:25        at hudson.remoting.Channel.call(Channel.java:1000)
17:00:25        at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution.run(CommandStep.java:72)
17:00:25        at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution.lambda$start$0(SSHStepExecution.java:84)
17:00:25        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
17:00:25        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
17:00:25        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
17:00:25        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
17:00:25        at java.base/java.lang.Thread.run(Thread.java:834)
17:00:25  com.jcraft.jsch.JSchException: Auth fail

jenkins groovy ssh-agent
1个回答
0
投票

删除了 ssh-agent 并使用 withCredentials。

© www.soinside.com 2019 - 2024. All rights reserved.