8

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?

2
  • Did you ever get this to work with .gitlab-ci.yml by any chance? Commented Apr 26, 2016 at 2:30
  • 1
    Yes! Works perfectly now :)! I'll post my solution below. Commented May 3, 2016 at 12:18

2 Answers 2

11

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 
Sign up to request clarification or add additional context in comments.

2 Comments

Small hint for windows users... commands like "npm install" doesn't work, you have to use "call npm install".
It has something to do with npm on Windows being really a npm.cmd, so when Gitlab CI runs it (using something like "cmd /c npm.cmd ...") when npm.cmd finishes it actually exists the cmd, so ends the whole job. Not too sure, but something like this.
4

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.

1 Comment

Very useful, thanks for sharing! To me, it was useful to say karma start --single-run to make it just run once.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.