In this case, docker run container with "docker run -t -d -u 1001:1001" where 1001 its user Jenkins in host system, but into container his dont know who is 1001. I think we must mount /etc/passwd in container -v /etc/passwd:/etc/passwd:ro but this way insecure.
pipeline
node {
stage "Container Prep"
docker.image('maven:3.3.3-jdk-8').inside {
stage 'Checkout'
git url: 'https:
stage 'Build'
sh "whoami"
sh "id"
sh "cat /etc/passwd"
}
}
output
[Pipeline] node
Running on jenkins-slave-2 in /var/jenkins_home/workspace/docker-test
[Pipeline] {
[Pipeline] stage (Container Prep)
Using the 'stage' step without a block argument is deprecated
Entering stage Container Prep
Proceeding
[Pipeline] sh
[docker-test] Running shell script
+ docker inspect -f . maven:3.3.3-jdk-8
.
[Pipeline] withDockerContainer
$ docker run -t -d -u 1001:1001 -w /var/jenkins_home/workspace/docker-test -v /var/jenkins_home/workspace/docker-test:/var/jenkins_home/workspace/docker-test:rw -v /var/jenkins_home/workspace/docker-test@tmp:/var/jenkins_home/workspace/docker-test@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat maven:3.3.3-jdk-8
[Pipeline] {
[Pipeline] stage (Checkout)
Using the 'stage' step without a block argument is deprecated
Entering stage Checkout
Proceeding
[Pipeline] git
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https:Fetching upstream changes from https: > git --version # timeout=10
> git fetch --tags --progress https: > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 9380caff2d46132c7e7a484c6aba02ac976642d0 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 9380caff2d46132c7e7a484c6aba02ac976642d0
> git branch -a -v --no-abbrev # timeout=10
> git branch -D master # timeout=10
> git checkout -b master 9380caff2d46132c7e7a484c6aba02ac976642d0
> git rev-list 9380caff2d46132c7e7a484c6aba02ac976642d0 # timeout=10
[Pipeline] stage (Build)
Using the 'stage' step without a block argument is deprecated
Entering stage Build
Proceeding
[Pipeline] sh
[docker-test] Running shell script
+ whoami
whoami: cannot find name for user ID 1001
[Pipeline] }
$ docker stop --time=1 7855fa17acd5dd71b5649be5d1e28b6d0c990953c58e044e469d779e86917842
$ docker rm -f 7855fa17acd5dd71b5649be5d1e28b6d0c990953c58e044e469d779e86917842
[Pipeline] [Pipeline] }
[Pipeline] [Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
Same in docker: https://github.com/docker/docker/issues/22323
Seems related to https://issues.jenkins-ci.org/browse/JENKINS-38438