sandeshdaundkar
sandeshdaundkar

Reputation: 903

npm: command not found - Gitlab CI specific runner

I am running gitlab-runner on my server, I am not using docker for deployment. I am trying to achieve the deployment on a remote server by doing ssh to the server. This is my .gitlab-ci.yml file -

stages:
  - deploy

pre-staging:
  stage: deploy
  environment:
    name: Gitlab CI/CD for pre-staging deployment
    url: "$REMOTE_SERVER"
  before_script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - mkdir -p ~/.ssh
    - eval $(ssh-agent -s)
    - 'echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  script:
    - ssh-add <(echo "$REMOTE_PVT_KEY")
    - ssh ubuntu@"$REMOTE_SERVER" "cd deployment_container; npm --version ;rm -rf static; source deploy.sh"
    - echo "Deployment completed"
  only:
    - megre_requests
    - pre-staging
  tags:
    - auto-deploy

My pipeline is failing with error npm: command not found. I have proper environment for npm on my ssh-ed server. I am trying to deploy the Django-react application. I have already tried using image: node:latest. npm is installed using nvm

Can somebody help me resolve this?

Upvotes: 1

Views: 2915

Answers (3)

Mahabub Azam
Mahabub Azam

Reputation: 51

You can try this one.

stages:
          - build
          - deploy

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

Upvotes: 0

sandeshdaundkar
sandeshdaundkar

Reputation: 903

In this we have to give npm access to all users by executing below command,

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

This resolved my issue of npm: command not found

Upvotes: 0

VonC
VonC

Reputation: 1326716

Try and replace the ssh step with:

ssh ubuntu@"$REMOTE_SERVER" "pwd; cd deployment_container; echo $PATH"

If this "deployment" (which won't do anything) completes, it means npm is not accessible in the default PATH defined in the SSH session.

Upvotes: 1

Related Questions