简体   繁体   中英

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

I have setup an AWS Codepipeline.

The pipeline uses Git as a source, Jenkins for testing and an EC2 instance for deployment.

The project is based on Angular Starter by Angular Class . Thus, it uses Karma for unit testing.

The Jenkins service runs on Ubuntu 16.04.

Karma uses Headless Chrome for testing.

The problem is that I currently get the folloing error when running the tests on 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
  • give jenkins user root privileges (I know it is dangerous but I just wanted to try if it would work) -> result: error still exists
  • allow jenkins user to run scripts with sudo -> result: nvm, npm and node is not defined; I tried to install nvm, npm and node manually but got a new error permission denied /root/.nvm

npm log file output looks as follows:

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. Provide Jenkins user sudo permissions through base installation of node, and then use commands "sudo command".

I was facing a similar issue and was able to resolve by installing Chrome. Note that you may have to set CHROME_BIN environment variable as well.

For reference: I was running Jenkins inside Docker. 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). 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' }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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