2017-02-13 141 views
1

我目前得到了配置有三個階段,我gitlab-ci.yaml文件: - 測試 - 部署 - 發佈Gitlab CI:構建成功,即使NPM錯誤

有時會出現錯誤的NPM如果我或開發人員忘記到--save一個NPM包,-test階段沒有正確完成,但仍然返回「構建通過」。隨着管道未被取消,它將盲目地部署和發佈。

如何製作NPM ERR!停止當前階段並停止其餘的運行?

我通過故意省略bluebird軟件包來模擬此問題。它影響了整個測試/部署/發佈過程,基本上糟糕的代碼部署和我的服務器上運行:

myClass.js 
    .selectSpecificXYZ() 
     1) Should return an object containing SUCCESS 
     2) should return an object regardless of the input 
     3) should return an object with count 0 
     4) should return an ABC error 
     5) should return a DEF error 

    Array 
    #indexOf() 
     ✓ should return -1 when the value is not present 


    1 passing (87ms) 
    5 failing 

    1) myClass.js .selectSpecificXYZ() Should return an object containing SUCCESS when a correct myClass reference is passed: 
    Error: Cannot find module 'bluebird' 
     at require (internal/module.js:20:19) 
     at Object.<anonymous> (api_system/functions/helpers/database_wrappers.js:5:15) 
     at require (internal/module.js:20:19) 
     at Object.selectXYZByReference (api_system/functions/myClass/myClass.js:55:37) 
     at Context.it (api_system/test/myClass/myClassTests.js:19:32) 

    2) myClass.js .selectSpecificXYZ() should return an object regardless of the input (to handle success or error): 
    Error: Cannot find module 'bluebird' 
     at require (internal/module.js:20:19) 
     at Object.<anonymous> (api_system/functions/helpers/database_wrappers.js:5:15) 
     at require (internal/module.js:20:19) 
     at Object.selectXYZByReference (api_system/functions/myClass/myClass.js:55:37) 
     at Context.it (api_system/test/myClass/myClassTests.js:23:32) 

    3) myClass.js .selectSpecificXYZ() should return an object with count 0 as there's no value: 
    Error: Cannot find module 'bluebird' 
     at require (internal/module.js:20:19) 
     at Object.<anonymous> (api_system/functions/helpers/database_wrappers.js:5:15) 
     at require (internal/module.js:20:19) 
     at Object.selectXYZByReference (api_system/functions/myClass/myClass.js:55:37) 
     at Context.it (api_system/test/myClass/myClassTests.js:27:30) 

    4) myClass.js .selectSpecificXYZ() should return an Invalid Parameter error : 
    AssertionError: expected [Function] to throw error including 'Invalid Parameter' but got 'Cannot find module \'bluebird\'' 
     at Context.it (api_system/test/myClass/myClassTests.js:33:73) 

    5) myClass.js .selectSpecificXYZ() should return an Parameter Too Short error: 
    AssertionError: expected [Function] to throw error including 'Parameter Too Short' but got 'Cannot find module \'bluebird\'' 
     at Context.it (api_system/test/myClass/myClassTests.js:38:79) 




npm ERR! Linux 4.4.34-v7+ 
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test" "-recursive" 
npm ERR! node v7.2.1 
npm ERR! npm v3.10.10 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] test: `mocha api_system/test --recursive` 
npm ERR! Exit status 5 
npm ERR! 
npm ERR! Failed at the [email protected] test script 'mocha api_system/test --recursive'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the myServer package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  mocha api_system/test --recursive 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs myServer 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls myServer 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  /var/www/ci-tests/myServer/npm-debug.log 
[32;1m$ cd ..[0;m 
[32;1m$ rm -rf myServer[0;m 
[32;1m$ cd ..[0;m 
[32;1m$ rm -rf ci-tests[0;m 
[32;1m$ EOF[0;m 
[32;1mBuild succeeded 
[0;m 

回答

1

您不包括您特拉維斯 - CI配置或者,你必須運行一切的劇本,但對於例如,當您有腳本時:即使註釋返回錯誤,腳本仍然可以退出併成功退出。你可以做的是:

#!/bin/sh 
npm install \ 
&& npm test \ 
|| exit 1 

確保腳本本身將錯誤返回給操作系統。這是一個不是特定於GitLab的通用建議,但是我不能發佈任何更具體的,沒有看到你的配置和你的腳本。