ncux199rus
ncux199rus

Reputation: 125

Pipeline when copying to a remote host gives an error - `unknown user`

Pipeline returns the error 'unknown user 111` because there is no jenkins user in the container!

What could be the problem? Maybe I'm using ssh-agent incorrectly.

If you look at the docker agent, there is no jenkins user. But the ssh agent Username is jenkins.

Jenkinsfile:

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 [email protected]:/home/jenkins/
                    '''
                }
            }
        }
    }
}

Console Output:


[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 [email protected]:/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```

Upvotes: 1

Views: 599

Answers (1)

Emiroe
Emiroe

Reputation: 56

The problem is that you are using the ssh-agent incorrectly. The ssh-agent is trying to connect to the remote server using the 'jenkins' user, but that user does not exist in the container that you are using as the Jenkins agent.

One solution would be to add the 'jenkins' user to the container image. Alternatively, you can specify a different user for the ssh-agent to use when connecting to the remote server.

Upvotes: 1

Related Questions