用npm设置Rails的GitLab CI

这些天,我正在为我的项目而苦恼于GitLab CI设置。 这个设置并不像Travis CI那么简单。 我花了很多时间debugging这个,所有我发现不符合我的要求

上下文

我有一个使用rvmnpmpostgresql的Rails项目。 我用rvmnpm安装了一个定制的Docker镜像。 但是,在运行之前,我必须得到我的.gitlab-ci.yml相应的rubynode版本:

 image: "my-rvm-npm-image" services: - postgres:9.3-alpine variables: POSTGRES_DB: db POSTGRES_USER: user POSTGRES_PASSWORD: cache: untracked: true key: "$CI_BUILD_REF_NAME" paths: - node_modules/ stages: - build - rspec - npm build: stage: build script: - sudo chown -R $(whoami) /cache - /bin/bash -l -c "rvm install $(cat .ruby-version) && rvm use $(cat .ruby-version) && gem install bundle && bundle install --jobs $(nproc) --path /cache && source ~/.nvm/nvm.sh && nvm install && npm install npm -g && npm install && bundle exec rake db:test:prepare" rspec: stage: rspec script: - bundle exec rake npm: stage: npm script: - npm test 

请注意,这个.gitlab-ci.yml文件仍然failed 。 在GitLab运行器configuration中, bundle install将位于/cache中:

 [[runners]] name = "xxxx" url = "URLabc.com" token = "myprojectoken" executor = "docker" [runners.docker] tls_verify = false image = "my-rvm-npm-image" privileged = true disable_cache = false volumes = ["/home/ci/cache:/cache", "/home/ci/builds:/builds"] [runners.cache] 

buildscache文件夹是主机绑定的。 这样我可以保留下一个版本的bundle install cache。

我的问题

build工作通行证,但是rspecnpm失败/bin/bash: bundle: command not found 。 看来这个bundle不会传递给其他工作。 我知道我应该使用artifacts传递给其他工作,但我已经把它作为caching,我应该有

我想实现这些目标:

  • 每次运行cachingbundle install ,因为从头开始需要rspec分钟的时间来重build,并传递给rspec作业来运行testing。
  • 还从npm installcachingnode_modules并传递给npm作业。
  • 任何关于rvmnpm安装的build议,因为我不想在每个命令之前使用丑陋的方式bash -l -c