我正在运行一个Github动作工作流。下面是代码:
name: Deploy to EC2
on:
workflow_dispatch: # Manual trigger
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Transfer code to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
source: . # Copy all files from the repository root
target: /home/ubuntu/app/next/
- name: SSH into EC2 and Run Script
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd /home/ubuntu/app
cd next
npm ci
npm run build
pm2 restart 0
当我运行工作流时,它抛出了这个错误:
======CMD======
cd /home/***/app
cd next
npm ci
npm run build
pm2 restart 0
======END======
err: bash: line 3: npm: command not found
err: bash: line 4: npm: command not found
2023/06/13 03:31:13 Process exited with status 127
err: bash: line 5: pm2: command not found
我在我的ec2示例上全局配置了npm和pm2。但它每次都抛出这个错误。我试过不同的方法,但不起作用
1条答案
按热度按时间yqlxgs2m1#
我也有同样的问题。最后,我找到了解决办法。我使用它的方法是在我的项目的根目录中创建一个bash脚本:pm2_runner.sh,我添加了:
pm2_runner.sh文件中。
然后在.github/workflow/中的.yml文件中添加了2行
这里.yml文件
更多信息:Github Actions pm2: command not found