我正在跟随有关Jenkins管道的教程,我可以在Node 6.10 Docker容器下运行“hello world”。
但是,当我将默认的EmberJS应用程序(使用ember init
)添加到存储库并尝试在管道中构建它时,在运行npm install时会失败(因为目录访问问题)。 Jenkinsfile可以在此处查看:https://github.com/CloudTrap/pipeline-tutorial/blob/fix-build/Jenkinsfile
构建打印的错误消息是(本地安装并在Macbook上使用java -jar jenkins.war
运行,与问题无关但包含在内):
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.
注意:我希望不以root / sudo身份运行npm install。
更新:我已经取得了一些进展,如下所示:
我在日志中找到了Jenkins使用容器构建的命令:
[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
当docker镜像运行时,它的工作目录是一个名为
/long-workspace-directory
的路径(实际上是一个看起来很神秘的jenkins工作空间路径),用户ID为501(组ID为20),等等。该用户没有名称(显然这破坏了与此问题无关的其他内容)。
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.
npm install
,这被认为是非常不好的做法。我希望避免这种情况。 - les2