在码头工人的jenkins管道中,npm安装失败 [英] npm install fails in jenkins pipeline in docker
问题描述
但是,当我添加默认的EmberJS应用程序(使用 ember init
)到repo并尝试在管道中构建,它在运行npm安装(由于目录访问问题)时失败。 Jenkins文件可以在这里看到: https://github.com/CloudTrap / pipeline-tutorial / blob / fix-build / Jenkinsfile
构建所打印的错误消息是(本地安装的,使用 java -jar jenkins.war
在Macbook上,不相关但仅包括以下情况)是:
npm ERR! Linux 4.9.12-moby
npm ERR! argv/ usr / local / bin / node/ usr / local / bin / npminstall
npm ERR!节点v6.10.0
npm ERR! npm v3.10.10
npm ERR!路径/.npm
npm ERR!代码EACCES
npm ERR! errno -13
npm ERR!系统调用mkdir
npm ERR!错误:EACCES:permission denied,mkdir'/.npm'
npm ERR! at error(native)
npm ERR! {错误:EACCES:permission denied,mkdir'/.npm'
npm ERR! at error(native)
npm ERR! errno:-13,
npm ERR!代码:'EACCES',
npm ERR!系统调用:'mkdir',
npm ERR!路径:'/.npm',
npm ERR! parent:'pipeline-tutorial'}
npm ERR!
npm ERR!请尝试以root / Administrator身份再次运行此命令。
注意:我想不运行 npm安装
作为root / sudo。
更新:我已经能够取得一些进展如下:
我发现Jenkins使用从日志中使用容器构建的命令:
[管道] withDockerContainer
$ docker运行-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工作空间路径),用户标识是501(组ID 20)等。用户没有名称(这显然是打破了与此问题无关的其他事项)。
-
更改代理使用一个Dockefile:
代理{
dockerfile {
文件名称'Dockerfile'
args'-v /.cache/ -v /.bower/ -v /.config/configstore/'
}
} - 指定
args'-v ...'
,用于为npm install / bower需要的目录创建卷。 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_config_cache = npm-cache'
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).
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.
'npm_config_cache=npm-cache'
这篇关于在码头工人的jenkins管道中,npm安装失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!