Search code examples
deploymentcontinuous-integrationgithub-actionsdigital-oceanpm2

How to configure pm2 to trigger from github action


I have step in github action file

        uses: appleboy/[email protected]
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USER }}
          port: ${{ secrets.SSH_PORT }}
          key: ${{ secrets.SSH_KEY }}
          script: |
            chown -R root /opt/project
            cd /opt/project
            yarn
            npm run pm2:start

package json file

pm2:start: /usr/local/bin/pm2 restart ecosystem.config.js --time 

also tried like pm2 restart ecosystem.config.js --time

on serve pm2 path

pm2: /usr/local/bin/pm2 /root/.nvm/versions/node/v16.19.1/bin/pm2

When I see action logs it throws an error (pm2: not found), what's wrong ?

34
err: warning " > [email protected]" has unmet peer dependency "express@>=4.0.0".
35
err: warning Workspaces can only be enabled in private projects.
36
out: [4/4] Building fresh packages...
37
out: Done in 56.73s.
38
out: > [email protected] pm2:start
39
out: > /usr/local/bin/pm2 restart ecosystem.config.js --time
40
err: sh: 1: /usr/local/bin/pm2: not found
40
2023/04/16 05:36:21 Process exited with status 127

Solution

  • You need to add the absolute path of pm2 to PATH environment variable before invoking it.

    See these relevant threads: