大家好,我正试图用docker和jenkins创建一个管道,在容器中执行npm install
时遇到以下错误
$ docker run -t -d -u 1001:1001 -w
/home/jenkins/jenkins_slave/workspace/SistacLabAPI -v /home/jenkins/jenkins_slave/workspace/SistacLabAPI:/home/jenkins/jenkins_slave/workspace/SistacLabAPI:rw -v /home/jenkins/jenkins_slave/workspace/SistacLabAPI@tmp:/home/jenkins/jenkins_slave/workspace/SistacLabAPI@tmp:rw jorgebo10/slapi:jenkins-SistacLabAPI-125 cat
[Pipeline] {
[Pipeline] sh
[SistacLabAPI] Running shell script
+ pwd
/home/jenkins/jenkins_slave/workspace/SistacLabAPI
[Pipeline] sh
[SistacLabAPI] Running shell script
+ ls -l
total 280
-rw-rw-r-- 1 1001 1001 316 Jul 26 23:06 Dockerfile
-rw-rw-r-- 1 1001 1001 1331 Jul 26 19:27 Gruntfile.js
-rw-rw-r-- 1 1001 1001 11357 Jul 26 19:27 LICENSE
drwxrwxr-x 4 1001 1001 4096 Jul 26 19:27 app
-rw-rw-r-- 1 1001 1001 926 Jul 26 19:27 app.js
drwxrwxr-x 3 1001 1001 4096 Jul 26 19:27 config
drwxr-xr-x 2 1001 1001 4096 Jul 27 15:29 jorge
-rw-r--r-- 1 1001 1001 240093 Jul 27 15:28 npm-debug.log
-rw-rw-r-- 1 1001 1001 1348 Jul 26 19:27 package.json
drwxrwxr-x 2 1001 1001 4096 Jul 26 19:27 public
[Pipeline] sh
[SistacLabAPI] Running shell script
+ hostname
61162ea48f0b
[Pipeline] sh
[SistacLabAPI] Running shell script
+ node -v
v4.4.7
[Pipeline] sh
[SistacLabAPI] Running shell script
+ npm install
npm ERR! Linux 3.13.0-92-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v4.4.7
npm ERR! npm v2.15.8
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! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/.npm',
npm ERR! parent: 'sistacLabAPI' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /home/jenkins/jenkins_slave/workspace/SistacLabAPI/npm-debug.log
[Pipeline] }
$ docker stop 61162ea48f0b6044cf3b1b9d763d1b098b21af87b152901c64610df4b0060c22
$ docker rm -f 61162ea48f0b6044cf3b1b9d763d1b098b21af87b152901c64610df4b0060c22
我的詹金斯文件有以下内容
node('docker') {
git url: 'https://github.com/jorgebo10/SistacLabAPI.git', branch:'development'
docker.build("jorgebo10/slapi:${env.BUILD_TAG}").inside {
sh "pwd"
sh "ls -l"
sh "hostname"
sh "node -v"
sh "npm install"
}
input '¿Deploy to production?'
stage 'Production'
}
有关于可能发生的事情的线索吗?似乎以用户1001的身份运行npm install是不好的。
谢谢,Jorge
如本文所述
用包装你的舞台
withEnv(['HOME=.']) {
...
...
}