简体   繁体   English

如何解决错误:在运行Karma时在Jenkins上产生EACCES?

[英]How to solve Error: spawn EACCES on Jenkins when running Karma?

I have setup an AWS Codepipeline. 我已经设置了AWS Codepipeline。

The pipeline uses Git as a source, Jenkins for testing and an EC2 instance for deployment. 该管道使用Git作为源,Jenkins用于测试,使用EC2实例进行部署。

The project is based on Angular Starter by Angular Class . 该项目基于Angular Class的Angular Starter Thus, it uses Karma for unit testing. 因此,它使用Karma进行单元测试。

The Jenkins service runs on Ubuntu 16.04. Jenkins服务在Ubuntu 16.04上运行。

Karma uses Headless Chrome for testing. Karma使用Headless Chrome进行测试。

The problem is that I currently get the folloing error when running the tests on Jenkins: 问题是我在Jenkins上运行测试时遇到了以下错误:

[31m07 05 2017 14:30:35.779:ERROR [karma]: [39m{ Error: spawn EACCES
    at exports._errnoException (util.js:1050:11)
    at ChildProcess.spawn (internal/child_process.js:319:11)
    at exports.spawn (child_process.js:378:9)
    at spawnWithoutOutput (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/process.js:168:24)
    at Object.ProcessLauncher._execCommand (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/process.js:76:21)
    at Object.ProcessLauncher._start (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/process.js:33:10)
    at Object.<anonymous> (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/process.js:19:10)
    at emitOne (events.js:101:20)
    at Object.emit (events.js:191:7)
    at Object.BaseLauncher.start (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launchers/base.js:42:10)
    at Object.j (/var/lib/jenkins/workspace/ExampleTask/node_modules/karma/lib/launcher.js:116:17)
    at Object.setTimeout.bind.j (/var/lib/jenkins/workspace/ExampleTask/node_modules/qjobs/qjobs.js:143:18)
    at ontimeout (timers.js:386:14)
    at tryOnTimeout (timers.js:250:5)
    at Timer.listOnTimeout (timers.js:214:5) code: 'EACCES', errno: 'EACCES', syscall: 'spawn' }

I have already done some research with the following findings: 我已经做了一些研究,结果如下:

  • other people also had similar errors but related to to other packages 其他人也有类似的错误,但与其他包相关
  • the error may be related to wrong permissions 该错误可能与错误的权限有关

What I have tried so far: 到目前为止我尝试过的:

  • checking the permissions of /var/lib/jenkins/workspace/ExampleTask -> result: owner is jenkins user 检查/ var / lib / jenkins / workspace / ExampleTask - > result的权限:owner是jenkins用户
  • give jenkins user root privileges (I know it is dangerous but I just wanted to try if it would work) -> result: error still exists 给jenkins用户root权限(我知道它很危险,但我只想尝试它是否可行) - >结果:错误仍然存​​在
  • allow jenkins user to run scripts with sudo -> result: nvm, npm and node is not defined; 允许jenkins用户使用sudo运行脚本 - >结果:nvm,npm和node未定义; I tried to install nvm, npm and node manually but got a new error permission denied /root/.nvm 我尝试手动安装nvm,npm和节点,但得到了一个新的错误permission denied /root/.nvm

npm log file output looks as follows: npm日志文件输出如下:

0 info it worked if it ends with ok
1 verbose cli [ '/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin/node',
1 verbose cli   '/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin/npm',
1 verbose cli   'run',
1 verbose cli   'test' ]
2 info using npm@4.2.0
3 info using node@v7.10.0
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle  example@0.0.1~pretest:  example@0.0.1
6 silly lifecycle  example@0.0.1~pretest: no script for pretest, continuing
7 info lifecycle  example@0.0.1~test:  example@0.0.1
8 verbose lifecycle  example@0.0.1~test: unsafe-perm in lifecycle true
9 verbose lifecycle  example@0.0.1~test: PATH: /var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/lib/node_modules/npm/bin/node-gyp-bin:/var/lib/jenkins/workspace/ExampleTask/node_modules/.bin:/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/lib/node_modules/npm/bin/node-gyp-bin:/var/lib/jenkins/workspace/ExampleTask/node_modules/.bin:/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
10 verbose lifecycle  example@0.0.1~test: CWD: /var/lib/jenkins/workspace/ExampleTask
11 silly lifecycle  example@0.0.1~test: Args: [ '-c', 'npm run lint && karma start' ]
12 silly lifecycle  example@0.0.1~test: Returned: code: 1  signal: null
13 info lifecycle  example@0.0.1~test: Failed to exec test script
14 verbose stack Error:  example@0.0.1 test: `npm run lint && karma start`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:194:7)
14 verbose stack     at ChildProcess.<anonymous> (/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:194:7)
14 verbose stack     at maybeClose (internal/child_process.js:899:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid  example@0.0.1
16 verbose cwd /var/lib/jenkins/workspace/ExampleTask
17 error Linux 4.4.0-1016-aws
18 error argv "/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin/node" "/var/lib/jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_7.10.0/bin/npm" "run" "test"
19 error node v7.10.0
20 error npm  v4.2.0
21 error code ELIFECYCLE
22 error errno 1
23 error  example@0.0.1 test: `npm run lint && karma start`
23 error Exit status 1
24 error Failed at the  example@0.0.1 test script 'npm run lint && karma start'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the  example package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     npm run lint && karma start
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs  example
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls  example
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]

Jenkins node plugin doesn't have correct permissions to perform specific tasks. Jenkins节点插件没有执行特定任务的正确权限。 Provide Jenkins user sudo permissions through base installation of node, and then use commands "sudo command". 通过基本安装节点提供Jenkins用户sudo权限,然后使用命令“sudo command”。

I was facing a similar issue and was able to resolve by installing Chrome. 我遇到了类似的问题,可以通过安装Chrome来解决问题。 Note that you may have to set CHROME_BIN environment variable as well. 请注意,您可能还必须设置CHROME_BIN环境变量。

For reference: I was running Jenkins inside Docker. 供参考:我在Docker中运行Jenkins。 The js project installed chromedriver as a dependency and I was setting CHROME_BIN to the chromedriver and received the same issue you mentioned (my stack trace is below). js项目安装了chromedriver作为依赖项,我将CHROME_BIN设置为chromedriver并收到了你提到的相同问题(我的堆栈跟踪如下)。 Hopefully this is some help or at least helps you moving, good luck. 希望这是一些帮助或至少帮助你移动,祝你好运。

03 01 2018 02:01:20.288:ERROR [karma]: { Error: spawn EACCES
at exports._errnoException (util.js:1020:11)
at ChildProcess.spawn (internal/child_process.js:328:11)
at exports.spawn (child_process.js:370:9)
at spawnWithoutOutput (/var/jenkins_home/jobs/oh2.0 test/workspace/node_modules/karma/lib/launchers/process.js:168:24)
at Object.ProcessLauncher._execCommand (/var/jenkins_home/jobs/oh2.0 test/workspace/node_modules/karma/lib/launchers/process.js:76:21)
at Object.ProcessLauncher._start (/var/jenkins_home/jobs/oh2.0 test/workspace/node_modules/karma/lib/launchers/process.js:33:10)
at Object.<anonymous> (/var/jenkins_home/jobs/oh2.0 test/workspace/node_modules/karma/lib/launchers/process.js:19:10)
at emitOne (events.js:101:20)
at Object.emit (events.js:188:7)
at Object.BaseLauncher.start (/var/jenkins_home/jobs/oh2.0 test/workspace/node_modules/karma/lib/launchers/base.js:42:10)
at Object.j (/var/jenkins_home/jobs/oh2.0 test/workspace/node_modules/karma/lib/launcher.js:116:17)
at Object.setTimeout.bind.j (/var/jenkins_home/jobs/oh2.0 test/workspace/node_modules/qjobs/qjobs.js:143:18)
at ontimeout (timers.js:386:11)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5) code: 'EACCES', errno: 'EACCES', syscall: 'spawn' }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM