0

i am using pm2 in the shell and it works fine. But when i add it to .travis.yml, it shows me

$ pm2 restart index.js
No command 'pm2' found

pm2 is in /usr/local/bin and when i echo $PATH, it includes the path /usr/local/bin。i know nothing about it.

.travis.yml

language: node_js
node_js:
- 8.9.1
branchs:
  only:
  - master
cache:
  apt: true
  directories:
  - node_modules
install:
- git pull
- rm -f package-lock.json && npm install
script:
- echo $PATH
- pm2 restart index.js
after_success:
- chmod 600 ~/.ssh/id_rsa
before_install:
- openssl aes-256-cbc -K $encrypted_a46a360c8512_key -iv $encrypted_a46a360c8512_iv
  -in id_rsa.enc -out ~/.ssh/id_rsa -d
Yeachan
  • 31
  • 8
  • pm2 is installed in your local machine. you need to follow this https://stackoverflow.com/questions/27837455/does-travis-ci-org-support-pm2 and add pm2 installation in tavis`s yaml file as well – molaga Mar 05 '19 at 07:14

1 Answers1

0

I think you have mixed up build container with the actual server where you want the final app to run.

Travis builds projects inside a VM/Container that ends when the Travis build ends. PM2 is supposed to be installed and run on the actual web server that hosts the app.

So, from Travis ci you probably should:

  1. Upload latest project files to the actual server via ssh.
  2. Run pm2 on the actual server via ssh.

Here's something along these lines: https://oncletom.io/2016/travis-ssh-deploy/

S.D.
  • 29,290
  • 3
  • 79
  • 130
  • Does this mean i only can run ```git pull``` in .travis.yml. And everytime i need to run pm2 with shell. – Yeachan Mar 06 '19 at 03:32