I'm following a tutorial about Jenkins pipeline and I can get a "hello world" working under at node 6.10 docker container.
But, when I added a default EmberJS app (using ember init
) to the repo and attempt to build that in the pipeline, it fails when running npm install (because of directory access issues). The Jenkinsfile can be seen here: https://github.com/CloudTrap/pipeline-tutorial/blob/fix-build/Jenkinsfile
The error message printed by the build is (which is installed locally and run using java -jar jenkins.war
on a Macbook, not relevant but included just in case) is:
npm ERR! Linux 4.9.12-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v6.10.0
npm ERR! npm v3.10.10
npm ERR! path /.npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/.npm'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, mkdir '/.npm'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/.npm',
npm ERR! parent: 'pipeline-tutorial' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
Note: I would like to not run npm install
as root / sudo.
UPDATE: I have been able to make some progress as follows:
I found the command that Jenkins uses to build using the container from the logs:
[Pipeline] withDockerContainer
$ docker run -t -d -u 501:20 -w /long-workspace-directory -v /long-workspace-directory:/long-workspace-directory:rw -v /long-workspace-directory@tmp:/long-workspace-directory@tmp:rw -e
So when the docker image runs, it's work directory is a /long-workspace-directory
(it's really a cryptic looking jenkins workspace path) and the user id is 501 (group id 20), etc. The user doesn't have a name (which is apparently breaking other things not related to this question).
Changed agent to use a Dockefile:
agent { dockerfile { filename 'Dockerfile' args '-v /.cache/ -v /.bower/ -v /.config/configstore/' } }
Specify
args '-v ...'
for creating volumes for the directories npm install / bower needs.
You can install
nvm
on the fly before building, in a local directory withNVM_DIR
without setting it as global dependency :The new locations are :
Having wasted a whole day on this issue, I found simply adding the following as an environment variable at the agent stage using the Pipeline Editor removed the problem.
from https://github.com/jenkins-infra/jenkins.io/blob/master/Jenkinsfile
Adding the environments and setting the Home to '.' solves this as below.
I add the same issue. I solved it using the
root
user to run the Docker image:You can override the user that Jenkins runs the docker container with, for example here I override with the root (userid:groupid is 0:0):
You can spot the current user in the
docker run
parameters in the console output.