mr.b
mr.b

Reputation: 2708

Gitlab CI Failed: NPM command not found

I have been playing around Gitlabl CI but for some reason I can't get my tests to "passed". It always says npm: command not found

My Gitlab CI config looks like this:

image: node:latest
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
  paths:
    - node_modules/

before_script:
  - npm install
  - npm install eslint -g
  - npm install eslint-plugin-react -g
  - npm install babel-eslint -g

test:lint:
  script:
    - eslint src/*

I keep getting the error below and I have No Idea why: enter image description here

By the way, Im NOT using the gitlab shared runner. Not sure if that contributes to the problem but just to make sure, the machine that has my gitlab runner has all the necessary packages to run nodejs.

Your help is greatly appreciated

Best regards,

Upvotes: 16

Views: 32521

Answers (8)

JrBriones
JrBriones

Reputation: 93

This worked greatly for me

    before_script:
    - apt-get update -qy
    - apt-get install --no-install-recommends -y npm
    - npm --version
    - npx --version
    - gem install dpl
    - npm install

Source: https://forum.gitlab.com/t/bin-bash-line-131-npm-command-not-found/70632/3

Upvotes: 0

Ali Raza Khan
Ali Raza Khan

Reputation: 1

If you are using sshpass to pass some command to your server, you'll have to update your .bashrc file (file path: ~/.bashrc).

In .bashrc file you see following code uncommented, comment it and it resolve your issue.

case $- in
    *i*) ;;
      *) return;;
esac

Upvotes: 0

Alan-Wen
Alan-Wen

Reputation: 109

In my case, there are two gitlab-runner. There is no node enviroment in the specific Runner.Then I stopped the wrong one

Upvotes: -1

Diptiman Mukherjee
Diptiman Mukherjee

Reputation: 229

You can use like below:-

stages:
          - build
          - deploy

deploy-prod:
          image: node:12.13.0-alpine
          stage: deploy
          script:
            - npm i -g firebase-tools

Upvotes: 2

Ayesha
Ayesha

Reputation: 311

Your cli is taking ssh executer by default. You probably need docker. Try adding tag in your yml script.

 tags: [ <your docker image name> ]

Upvotes: 0

Jorge Luis De la Cruz
Jorge Luis De la Cruz

Reputation: 11

This helped me:

n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

Upvotes: 0

孙勇健
孙勇健

Reputation: 1

I have same problem.

Gitlab-runner use user of 'gitlab-runner' default when it starts. So the user have not root access.

ps aux|grep gitlab-runner

  1. copy the shell of running

  2. change user: run /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user root in bash.

  3. gitlab-ci runner test

  4. pass!

  5. kill old pid

  6. nohup /usr/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user root

ps: gitlab-runner -u root also change user.

Upvotes: 0

Aashiq Parker
Aashiq Parker

Reputation: 807

The image tag specifies a docker image, hence you must specify the executor of your runner to be docker. Did you perhaps set it to be something else, like shell, when you created the runner?

Upvotes: 8

Related Questions