Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab CI/CD shell executor: npm command not found

On my server, I have configured the gitlab runner to use the shell executor. And which node command gives: /home/ubuntu/.nvm/versions/node/v14.11.0/bin/node.

So, my gitlab-ci.yml file has the following:

stages:
  - prepare
  - check
  - deploy

default:
  before_script:
    - export PATH=$PATH:/home/ubuntu/.nvm/versions/node/v14.11.0/bin

prepare:
  stage: prepare
  only:
    refs:
      - dev
  before_script:
    - export PATH=$PATH:/home/ubuntu/.nvm/versions/node/v14.11.0/bin
  script:
    - npm i --ignore-scripts --include=dev
  cache:
    key: $CI_COMMIT_BRANCH
    paths:
      - node_modules/

The prepare job, throws npm: command not found error, and the pipeline fails. How to resolve this issue?

like image 440
Azamat Abdullaev Avatar asked Oct 18 '25 15:10

Azamat Abdullaev


1 Answers

You can add to your script: step, before the npm command line:

- echo "PATH='${PATH}'"

That way, you can check if the path is actually modified.

Try adding quotes:

- export PATH="$PATH:/home/ubuntu/.nvm/versions/node/v14.11.0/bin"
like image 180
VonC Avatar answered Oct 21 '25 07:10

VonC