Docker Plugin for Jenkins Pipeline - No user exists for uid 1005

前端 未结 4 765
囚心锁ツ
囚心锁ツ 2021-02-12 23:10

I\'m trying to execute an SSH command from inside a Docker container in a Jenkins pipeline. I\'m using the CloudBees Docker Pipeline Plugin to spin up the container and execute

4条回答
  •  没有蜡笔的小新
    2021-02-12 23:30

    The solution provided by @nathan-thompson is awesome, but in my case I was unable to find the user even in the /etc/passwd of the host machine! It means mounting the passwd file did not fix the problem. This question https://superuser.com/questions/580148/users-not-found-in-etc-passwd suggested some users are logged in the host using an identity provider like LDAP.

    The solution was finding a way to add the proper line to the passwd file on the container. Calling getent passwd $USER on the host will provide the passwd line for the Jenkins user running the container.

    I added a step running on the node (and not the docker agent) to get the line and save it in a file. Then in the next step I mounted the generated passwd to the container:

    stages {
        stage('Create passwd') {
            steps {
                sh """echo \$(getent passwd \$USER) > /tmp/tmp_passwd
                """
            }
        }
        stage('Test') {
            agent {
                docker {
                    image '*******'
                    args '***** -v /tmp/tmp_passwd:/etc/passwd'
                    reuseNode true
                    registryUrl '*****'
                    registryCredentialsId '*****'
                }
            }
            steps {
                sh """ssh -i ********
                """
            }
        }
    }
    

提交回复
热议问题