13

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.

Aurora0001
  • 13,139
  • 5
  • 50
  • 53
Panshul
  • 1,064
  • 2
  • 14
  • 33
  • Please just try following the instructions for Debian installation: https://yarnpkg.com/lang/en/docs/install/#linux-tab and then post the results. So far it's failing because you haven't installed it. – Jakub Kania Mar 03 '17 at 11:53

5 Answers5

19

Solved it by using the latest official node docker image. Since image: 6.10.0, yarn is installed by default in the image.

But if you need node-gyp to build any package, it needs to be installed by adding a line to the script:

yarn global add node-gyp

Panshul
  • 1,064
  • 2
  • 14
  • 33
3

Add the following to your ci script after yarn got installed:

export PATH=$HOME/.yarn/bin:$PATH
  • In my case, I had a custom location set for npm packages so that they could be installed globally without `sudo`. Exporting the path at the beginning of my commands fixed it for me. – Christopher Bradshaw Jul 22 '20 at 17:20
2

I use image:node:latest and sometimes it prompts the error. Clear Runner Caches do the job for me. Maybe the runner did not recover to the correct state after doing other jobs.

W.Perrin
  • 4,217
  • 32
  • 31
1

I solved it by using npx (package runner). It's better then extending docker-image only for this purpose

npx yarn someCommand
Kas Elvirov
  • 7,394
  • 4
  • 40
  • 62
0

The issue is with the shell not knowing the path to yarn In the home folder for gitlab-runner you need to add the path to yarn in the startup files https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

Just add "export PATH=$PATH:/path/to/yarn" at the end of your startup files

erez taiar
  • 56
  • 3