2016-10-29 210 views
3

嗨,我想在gitlab上設置一個ci來運行每個提交和推送測試,但我不能設置配置yml文件可以任何請指導我我做錯了我當前的yml文件是Angular 2項目的Gitlab CI

image: node:4.2.2 
cache: 
    paths: 
    - node_modules/ 
test_app: 
    script: 
    - npm install 
    - npm test 

這是給我的錯誤安裝Phantom.js模塊的過程中,所以我嘗試了下面的配置,但顯示無效的語法。

image: node:4.2.2 

befor_script: 
    - mkdir ~/tmp 
    - pushd ~/tmp 
    - wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 
    - tar xf phantomjs-2.1.1-linux-x86_64.tar.bz2 
    - mv phantomjs-2.1.1-linux-x86_64 phantomjs 
    - ln -s ~/tmp/phantomjs/bin/phantomjs /usr/bin/phantomjs 
    - phantomjs --version 
    - cd .. 

cache: 
    paths: 
    - node_modules/ 

test_app: 
    script: 
    - npm install 
    - npm test 

我的package.json文件是

{ 
    "name": "test", 
    "version": "0.1.0", 
    "description": "My Angular2-TypeScript App", 
    "keywords": [ 
    "angular2", 
    "typescript", 
    "webpack" 
    ], 
    "scripts": { 
    "lint": "tslint \"src/**/*.ts\"", 
    "postinstall": "webdriver-manager update", 
    "e2e": "protractor", 
    "start": "gulp serve", 
    "build": "gulp build", 
    "test": "karma start" 
    }, 
    "dependencies": { 
    "@angular/common": "2.0.0", 
    "@angular/compiler": "2.0.0", 
    "@angular/core": "2.0.0", 
    "@angular/forms": "2.0.0", 
    "@angular/http": "2.0.0", 
    "@angular/platform-browser": "2.0.0", 
    "@angular/platform-browser-dynamic": "2.0.0", 
    "@angular/router": "3.0.0", 
    "@types/core-js": "^0.9.34", 
    "angular2-jwt": "^0.1.24", 
    "bootstrap": "^3.3.7", 
    "core-js": "^2.4.1", 
    "jquery": "^2.2.4", 
    "ng2-bootstrap": "^1.1.16", 
    "reflect-metadata": "^0.1.3", 
    "rxjs": "5.0.0-beta.12", 
    "zone.js": "^0.6.23" 
    }, 
    "devDependencies": { 
    "@types/jasmine": "^2.5.35", 
    "@types/node": "^6.0.45", 
    "@types/protractor": "^1.5.20", 
    "@types/selenium-webdriver": "2.44.28", 
    "codelyzer": "0.0.19", 
    "protractor": "^4.0.9", 
    "protractor-jasmine2-screenshot-reporter": "^0.3.2", 
    "gulp": "^3.9.1", 
    "gulp-load-plugins": "^1.3.0", 
    "gulp-shell": "^0.5.2", 
    "run-sequence": "^1.2.2", 
    "rimraf": "^2.5.2", 
    "tslint": "^3.13.0", 
    "typescript": "^2.0.3", 
    "css-loader": "^0.23.1", 
    "extract-text-webpack-plugin": "^1.0.1", 
    "file-loader": "^0.8.5", 
    "jasmine-core": "^2.4.1", 
    "karma": "^0.13.22", 
    "karma-coverage": "^1.0.0", 
    "karma-jasmine": "^0.3.8", 
    "karma-mocha-reporter": "^2.0.4", 
    "karma-phantomjs-launcher": "^1.0.0", 
    "karma-sourcemap-loader": "^0.3.7", 
    "karma-webpack": "^1.7.0", 
    "html-loader": "^0.4.3", 
    "html-webpack-plugin": "^2.15.0", 
    "null-loader": "^0.1.1", 
    "raw-loader": "^0.5.1", 
    "style-loader": "^0.13.1", 
    "ts-loader": "^0.8.1", 
    "webpack": "^1.13.1", 
    "webpack-dev-server": "^1.14.1", 
    "webpack-merge": "^0.14.0" 
    }, 
    "private": true 
} 

錯誤我得到

npm info build /builds/test/test/node_modules/rxjs/node_modules/symbol-observable 
npm info linkStuff [email protected] 
npm info install [email protected] 
npm info postinstall [email protected] 
npm info build /builds/test/test/node_modules/rxjs 
npm info linkStuff [email protected] 
npm info install [email protected] 
npm info postinstall [email protected] 
npm info [email protected] Failed to exec install script 
npm ERR! Linux 4.7.0-coreos-r1 
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" 
npm ERR! node v4.2.2 
npm ERR! npm v2.14.7 
npm ERR! code ELIFECYCLE 

npm ERR! [email protected] install: `node install.js` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node install.js'. 
npm ERR! This is most likely a problem with the phantomjs-prebuilt package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node install.js 
npm ERR! You can get their info via: 
npm ERR!  npm owner ls phantomjs-prebuilt 
npm ERR! There is likely additional logging output above. 
npm info preuninstall [email protected] 
npm info uninstall [email protected] 
npm info postuninstall [email protected] 
npm info preuninstall [email protected] 
npm info uninstall [email protected] 
npm info postuninstall [email protected] 

npm ERR! Please include the following file with any support request: 
npm ERR!  /builds/test/test/npm-debug.log 
ERROR: Build failed: exit code 1 

回答

2

我有同樣的問題,得到了最新的V6的NodeJS包解決了這個問題對我來說。

Ubuntu官方包的NodeJS是遠遠落後,安裝最新的NodeJS Ubuntu的V6包使用下面的命令:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - 
sudo apt-get install -y nodejs 
0

更新到第一個答案:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - 
sudo apt-get install -y nodejs 
0

對我的挑戰是運行e2e測試需要一個真正的瀏覽器運行。

現在Chrome還有--headless模式(甚至還有Debian軟件包),因此您不再需要PhantomJS(原因是其當前的維護人員已宣佈停止PhantomJS的計劃)。

關鍵是要在GitLab CI上啓動Chrome之前設置Xvfb。有關確切的設置代碼,請檢查How to run AngularJS end-to-end tests on GitLab CI