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

前端 未结 4 672
囚心锁ツ
囚心锁ツ 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:26

    I just found another solution to this problem, that I want to share. It differentiates from the existing solutions in that it allows to run the complete pipeline in one agent, instead of per stage.

    The trick is to, instead of directly using an image, refer to a Dockerfile (which may be build FROM the original) and then add the user:

    # Dockerfile
    FROM node
    
    ARG jenkinsUserId=
    RUN if ! id $jenkinsUserId; then \
        usermod -u ${jenkinsUserId} jenkins; \
        groupmod -g ${nodeId} jenkins; \
      fi
    
    // Jenkinsfile
    pipeline {
      agent {
        dockerfile {
          additionalBuildArgs "--build-arg jenkinsUserId=\$(id -u jenkins)"
        }
      }
    }
    

提交回复
热议问题