通过非交互式会话 SSH 连接到服务器时找不到命令

Command not found when SSHing into server via non-interactive session

我正在使用 GitHub 操作通过 SSH 连接到我的登台服务器以从存储库中提取最新版本(成功)然后安装节点模块:yarn(失败),构建应用程序:yarn build:app(失败),然后重新启动应用程序:pm2 restart all(失败)。从我从研究中读到的内容来看,没有找到命令,因为进入服务器的 SSH 是一个非交互式会话,很多东西都没有添加到 $PATH 中。我曾尝试将 export PATH="$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2" 添加到我的脚本中,但无济于事。我仍然找不到命令。

name: Test Deployment

on:
  push:
    branches:
      - staging

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Deploy Staging
        if: github.ref == 'refs/heads/staging'
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.STAGING_SSH_HOST }}
          username: ${{ secrets.STAGING_SSH_USERNAME }}
          key: ${{ secrets.STAGING_SSH_KEY }}
          passphrase: ${{ secrets.STAGING_SSH_PASSPHRASE }}
          port: ${{ secrets.STAGING_SSH_PORT }}
          script: |
            export PATH="$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2"
            cd ~/***
            git pull origin staging
            yarn
            yarn build:app
            pm2 restart all

接收错误:

======CMD======
export PATH="$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2"
cd ~/***
git pull origin staging
yarn
yarn build:app
pm2 restart all

======END======
err: From github.com:***/***
err:  * branch            staging    -> FETCH_HEAD
err:  ***  staging    -> origin/staging
out: Merge made by the 'recursive' strategy.
2021/04/16 21:28:17 Process exited with status 127
out:  .github/workflows/main.yml | 2 +-
out:  1 file changed, 1 insertion(+), 1 deletion(-)
err: bash: line 3: yarn: command not found
err: bash: line 4: yarn: command not found
err: bash: line 5: pm2: command not found

而不是

export path='$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2'

你应该试试

export PATH="$PATH:/home/***/.nvm/versions/node/v14.5.0/bin/pm2:/home/***/.nvm/versions/node/v14.5.0/bin/pm2"

通知:

  1. 路径 - 大写
  2. 使用双引号代替单引号扩展PATH变量的前一个值