简体   繁体   中英

Gitlab CI - npm' is not recognized as an internal or external command, operable program or batch file

I am trying to run a CI in gitlab

image: node:latest

stages:
  - deploy

production:
  stage: deploy
  before_script:
    - npm config set prefix /usr/local
    - npm install -g serverless
  script:
    - serverless deploy 

I am using the docker image like they suggest but it cannot find npm (or node)

How can I get this working?

Well, this is a bit weird, as your ci is correct.

If you are just using gitlab.com and their shared runners then this .gitlab-ci.yml will work.

One possible reason could be you have runners added as ssh/shell executors in the project repo. If so then the image tag you specified will be simply ignored.

So error like command not found could occur because of the server where you have added the runner doesn't have nodejs installed, and this error will occur for the npm config... command in before script with exit code 127 and pipeline will fail just there and stop.

If you have multiple runners then tag them and tag your jobs in ci.yml as well. And if you are trying to run the job on your own server then you got to install docker first.

BTW for docker image node:latest you don't need npm config set prefix /usr/local as it already is /usr/local

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM