I started working with the GitLab CI using the gitlab-ci-multi-runner for Windows (64bit). Everything works fine so far, there are connections to my repositories and my configured jobs get started on each push.
What I want to do now is having one job which runs npm install
to download all dependencies and one job which executes all my tests written with karma/jasmine by running karma start karma.conf.js
or using grunt and running grunt test
.
So the first job I tried was:
cd app
npm install
karma start karma.conf.js
The first two commands get executed, but the last one is completely ignored. So I tried to split the jobs. The first to commands get their own job (tab "run in parallel") and the last one was moved to its own job in the tab "run on success". Now all dependencies get installed and the second job starts. So far so good, but the second job starts with removing all previously installed dependencies and then tries to run karma start karma.conf.js
. This obviously ends up in failing all tests because the npm dependency "angular-mocks" was not downloaded. If I add npm install
to the second job (which does not make that much sense to me), the karma task will be ignored again.
What is the problem here? How can I fix this? And is there a way to not always download all dependencies on each test execution?
Since this question was posted, Gitlab CI has switched to using .gitlab-ci.yml
for config. I believe the recommended way to install dependencies is with a before_script
command such as
before_script:
- npm install
test:
script: npm test
I would like to post my final solution below, to help others with this issue. My .gitlab-ci.yaml file and my karma.conf.js are located in the app-root directory. For karma I'm using PhantomJS, which works great for Windows and also for my linux server.
Solution for Windows:
image: node:4.2.2
cache:
paths:
- node_modules/
stages:
- test
test_app:
stage: test
script:
- run npm install
- run karma start karma.conf.js
Currently I'm using a linux server for testing/building my apps. You have to remove the "run" to get this to work for linux.
If you have more than one job, you can move the dependency-installing commands to the "before_script" section like Tamlyn wrote above.
Please tell me, if it's still not working for you. Maybe I have some more ideas... I worked a lot on this, to get it working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With