2017-05-07 59 views
1

我已經設置了AWS Codepipeline。如何解決錯誤:在運行Karma時在Jenkins上產生EACCES?

該管道使用Git作爲源,Jenkins進行測試,並使用EC2實例進行部署。

該項目基於Angular Starter by Angular Class。因此,它使用Karma進行單元測試。

Jenkins服務在Ubuntu 16.04上運行。

Karma使用Headless Chrome進行測試。

的問題是,我目前得到詹金斯運行測試時folloing錯誤:

[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' } 

我已經做了一些研究與以下結果:

  • 其他人也有過類似的錯誤但與其他包有關
  • 錯誤可能與錯誤的權限有關

我迄今爲止嘗試:

  • 檢查的/ var/lib中/詹金斯/工作區的權限/ ExampleTask - > 結果:老闆是詹金斯用戶
  • 給詹金斯用戶root權限(我知道這是危險的,但我只是想嘗試,如果它會工作) - >結果:錯誤仍然存​​在
  • 允許jenkins用戶使用sudo運行腳本 - >結果:nvm,npm和節點未定義;我試圖手動安裝NVM,NPM和節點,但有一個新的錯誤permission denied /root/.nvm

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 [email protected] 
3 info using [email protected] 
4 verbose run-script [ 'pretest', 'test', 'posttest' ] 
5 info lifecycle [email protected]~pretest: [email protected] 
6 silly lifecycle [email protected]~pretest: no script for pretest, continuing 
7 info lifecycle [email protected]~test: [email protected] 
8 verbose lifecycle [email protected]~test: unsafe-perm in lifecycle true 
9 verbose lifecycle [email protected]~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 [email protected]~test: CWD: /var/lib/jenkins/workspace/ExampleTask 
11 silly lifecycle [email protected]~test: Args: [ '-c', 'npm run lint && karma start' ] 
12 silly lifecycle [email protected]~test: Returned: code: 1 signal: null 
13 info lifecycle [email protected]~test: Failed to exec test script 
14 verbose stack Error: [email protected] 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 [email protected] 
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 [email protected] test: `npm run lint && karma start` 
23 error Exit status 1 
24 error Failed at the [email protected] 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 ] 

回答

2

看起來你正在使用詹金斯節點插件,它不具備如果您可以嘗試使用節點的基本安裝,則提供正確的權限以執行特定的任務,爲Jenkins用戶提供sudo perms,然後使用「sudo命令」等命令可以爲您提供幫助。

0

我正面臨類似的問題,並能夠通過安裝Chrome來解決。請注意,您可能還必須設置CHROME_BIN環境變量。

僅供參考: 我在Docker內部運行Jenkins。 js項目安裝了chromedriver作爲依賴項,我將CHROME_BIN設置爲chromedriver並收到了您提到的相同問題(我的堆棧跟蹤如下)。希望這是一些幫助,或者至少可以幫助你移動,祝你好運。

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' } 
相關問題