patterndockerModerate
Jenkins: Permission issue using Docker as build environment
Viewed 0 times
jenkinsdockerpermissionissueenvironmentusingbuild
Problem
I installed Jenkins on an Ubuntu 16.04 machine. The Jenkins itself is not run in a container. What I want to do is simply call
Pretty straightforward, right?
jenkins user/group is
I tried to spin up the node container passing in argument
It looks like one or the other kind of issue, how can I work around that?
Jenkins logs:
Below is where the build starts and fails.
```
[Pipeline] sh
[Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2] Running shell script
+ docker inspect -f . node
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 112:116 -w /var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2 -v /var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2:/var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2:rw,z -v /var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2@tmp:/var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2@tmp:rw,z -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e **** --entrypoint cat
yarn install using a node image. So here is my Jenkinsfile:pipeline {
agent any
stages {
stage('install node modules...') {
agent { docker 'node' }
steps {
sh 'cd /path/to/package.json; yarn install'
}
}
}
}Pretty straightforward, right?
jenkins user/group is
112:116, and the uid of the node container is 1000, hence yarn process (which is run as node user 1000) can't do its things, like mkdir /.config.I tried to spin up the node container passing in argument
-u 1000, it bumped into permission issues when trying to create durable directories.It looks like one or the other kind of issue, how can I work around that?
Jenkins logs:
Below is where the build starts and fails.
```
[Pipeline] sh
[Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2] Running shell script
+ docker inspect -f . node
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 112:116 -w /var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2 -v /var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2:/var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2:rw,z -v /var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2@tmp:/var/lib/jenkins/workspace/Pipeline_Test_Jenkins_test-4JTFYMX7KSJY6ZH44VINNGEB7WH2D2HWYZN5ABF6O32O2HBQJYXQ@2@tmp:rw,z -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e -e **** --entrypoint cat
Solution
I had the same issue with node. The thing is files in the container are owned by "root:root". Try adding docker args
-u root:root:docker {
image 'node:8'
args '-u root:root'
}Code Snippets
docker {
image 'node:8'
args '-u root:root'
}Context
StackExchange DevOps Q#1937, answer score: 14
Revisions (0)
No revisions yet.