I am trying to configure my gitlab-ci to use yarn install
instead of npm install
My current gitlab-ci.yml looks like:
image: node:6.9.4
cache:
paths:
- node_modules/
- .yarn
before_script:
- apt-get update -qq && apt-get install -qy libelf1
stages:
- test
test_core:
stage: test
script:
- yarn config set cache-folder .yarn
- yarn install
- npm run build
- npm run test
tags:
- 2gb
But the build fails with the error:
/bin/bash: line 48: yarn: command not found
is there something I am missing? I tried installing yarn with:
curl -o- -L https://yarnpkg.com/install.sh | bash
this gave me same error, probably because I need to reload the bash environment for the yarn command to become available.
The above config works perfect with npm install
.
Please help me resolve this. If there is something missing in my config file or there is something wrong with the gitlab-ci. Thanks.
答案 0 :(得分:17)
使用最新的官方节点docker镜像解决了这个问题。
由于图像:6.10.0
,纱线默认安装在图像中。
但是如果您需要node-gyp
来构建任何包,则需要通过在脚本中添加一行来安装它:
yarn global add node-gyp
答案 1 :(得分:1)
安装纱线后,将以下内容添加到ci脚本中:
export PATH=$HOME/.yarn/bin:$PATH
答案 2 :(得分:0)
我使用npx
(程序包运行程序)解决了这个问题。最好仅为此目的扩展docker-image
npx yarn someCommand
答案 3 :(得分:0)
我使用 image:node:latest
有时它会提示错误。 Clear Runner Caches
为我完成工作。也许跑步者在做其他工作后没有恢复到正确的状态。