Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

test after build would run in new environment on gitlab-ci

I have the following configuration as .gitlab-ci.yml but I found out after successfully pass build stage (which would create a virtualenv called venv), it seems that in test stage you would get a brand new environment(there's no venv directory at all). So I wonder should I put setup script in before_script therefor it would run in each phase(build/test/deploy). Is it a right way to do it ?

before_script:
  - uname -r 

types:
  - build
  - test
  - deploy

job_install:
  type: build
  script:
    - apt-get update
    - apt-get install -y libncurses5-dev
    - apt-get install -y libxml2-dev libxslt1-dev
    - apt-get install -y python-dev libffi-dev libssl-dev 
    - apt-get install -y python-virtualenv
    - apt-get install -y python-pip
    - virtualenv --no-site-packages venv
    - source venv/bin/activate
    - pip install -q -r requirements.txt
    - ls -al
  only:
    - master

job_test:
  type: test
  script:
    - ls -al
    - source venv/bin/activate
    - cp crawler/settings.sample.py crawler/settings.py
    - cd crawler 
    - py.test -s -v 
  only:
    - master

adasd

like image 244
Chandler.Huang Avatar asked Jul 25 '15 07:07

Chandler.Huang


People also ask

Do GitLab stages run in parallel?

GitLab provides a method to make clones of a job and run them in parallel for faster execution using the parallel: keyword.


1 Answers

Gitlab CI jobs supposed to be independent, because they could run on different runners. It is not issue. There two ways to pass files between stages:

  • The right way. Using artefacts.
  • The wrong way. Using cache. With cache key "hack". Still need same runner.

So yes, supposed by gitlab way to have everything your job depends on in before script.

Artifacts example:

  artifacts:
   when: on_success
   expire_in: 1 mos
   paths:
    - some_project_files/

Cache example:

cache:
  key: "$CI_BUILD_REF_NAME"
  untracked: true
  paths:
   - node_modules/
   - src/bower_components/

For correct running environment i suggest using docker with image containing apt-get dependencies. And use artefacts for passing job results between jobs. Note that artefact also uploaded to gitlab web interface and being able to download them. So if they are quite heavy use small expire_in time, for removing them after all jobs done.

like image 89
MadDocNC Avatar answered Sep 19 '22 13:09

MadDocNC