jenkins 复制到远程主机时管道出现错误-“未知用户”

dly7yett  于 2023-01-16  发布在  Jenkins
关注(0)|答案(1)|浏览(183)

管道返回错误'unknown user 111',因为容器中没有jenkins用户!
可能是什么问题呢?可能我用错了ssh代理。
如果你看一下Docker代理,没有jenkins用户,但是ssh代理的用户名是jenkins。
Jenkins文件:

pipeline {
    agent {
        docker { 
            image 'node:10'
        }        
    }  
     environment {
        npm_config_cache='npm-cache'
    } 
    stages {
        stage('Build') {
            steps {
                echo "${BUILD_NUMBER}"
                echo "${USER}"
                sh "cat /etc/passwd"                     
            }
        }
        stage("ssh-agent") {
            steps {
                sshagent(['08a25aca-1fba-4e9a-a444-4211275436a4']) {
                    sh '''
                        scp ./test jenkins@192.168.120.13:/home/jenkins/
                    '''
                }
            }
        }
    }
}

控制台输出:

[Pipeline] echo
jenkins
[Pipeline] sh
+ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
node:x:1000:1000::/home/node:/bin/bash...
[Pipeline] sshagent
[ssh-agent] Using credentials jenkins (rnd-remote)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Exec ssh-agent (binary ssh-agent on a remote machine)
$ docker exec 81017287a7ae1e030c17a159dd71ab05e8623192dd55dc6ab111158d20e826b0 ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-w5tvOBaFFM5F/agent.29
SSH_AGENT_PID=36
Running ssh-add (command line suppressed)
Identity added: /var/lib/jenkins/workspace/vpp-config-object@tmp/private_key_7895885466712491331.key (jenkins@apkrnrnd)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
+ scp ./test jenkins@192.168.120.13:/home/jenkins/
unknown user 111
[Pipeline] }
$ docker exec --env ******** --env ******** 81017287a7ae1e030c17a159dd71ab05e8623192dd55dc6ab111158d20e826b0 ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 36 killed;
[ssh-agent] Stopped.
$ docker stop --time=1 81017287a7ae1e030c17a159dd71ab05e8623192dd55dc6ab111158d20e826b0
$ docker rm -f 81017287a7ae1e030c17a159dd71ab05e8623192dd55dc6ab111158d20e826b0
[Pipeline] End of Pipeline
ERROR: script returned exit code 255
Finished: FAILURE```
vd8tlhqk

vd8tlhqk1#

问题是您使用的ssh-agent不正确。ssh-agent试图使用'jenkins'用户连接到远程服务器,但您用作Jenkins代理的容器中不存在该用户。
一个解决方案是将'jenkins'用户添加到容器映像中,或者,您可以为ssh-agent指定一个不同的用户,以便在连接到远程服务器时使用。

相关问题