admin管理员组

文章数量:1401215

I have the following issue, I am trying to set up a GitHub action for continuous deployment, however, I run into issues which I think is caused by the chaining of commands for the SSH.

I'm looking for a cleaner solution and a fix to this.

Here's my hetzner.yml file:

name: Deploy to Hetzner
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up SSH
        uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY}}
      
      - name: (Finally) Deploy to Hetzner
        run: |
          ssh -v ${{ secrets.SSH_OPTS }} ${{ secrets.HETZNER_USER }}
          cd myproject
          git pull
          npm ci
          npm run build
          npm run start
          caddy run

Where, secrets.SSH_OPTS is: (note doublequotes inside)

"-o ServerAliveInterval=600 StrictHostKeyChecking=no"

And secrets.HETZNER_USER is:

[email protected] 

The error that I get is:

Run ssh -v *** *** cd myproject git pull npm ci npm run build npm run start caddy run
  ssh -v *** *** cd myproject git pull npm ci npm run build npm run start caddy run
  shell: /usr/bin/bash -e {0}
  env:
    SSH_AUTH_SOCK: /tmp/ssh-GLbX9AdHVKNp/agent.1757
    SSH_AGENT_PID: 1758
command-line line 0: keyword serveraliveinterval extra arguments at end of line
Error: Process completed with exit code 255.

Any help is much appreciated.

I tried putting the bash commands in single quotes, that works but isn't clean at all.

I have the following issue, I am trying to set up a GitHub action for continuous deployment, however, I run into issues which I think is caused by the chaining of commands for the SSH.

I'm looking for a cleaner solution and a fix to this.

Here's my hetzner.yml file:

name: Deploy to Hetzner
on:
  push:
    branches:
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up SSH
        uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY}}
      
      - name: (Finally) Deploy to Hetzner
        run: |
          ssh -v ${{ secrets.SSH_OPTS }} ${{ secrets.HETZNER_USER }}
          cd myproject
          git pull
          npm ci
          npm run build
          npm run start
          caddy run

Where, secrets.SSH_OPTS is: (note doublequotes inside)

"-o ServerAliveInterval=600 StrictHostKeyChecking=no"

And secrets.HETZNER_USER is:

[email protected] 

The error that I get is:

Run ssh -v *** *** cd myproject git pull npm ci npm run build npm run start caddy run
  ssh -v *** *** cd myproject git pull npm ci npm run build npm run start caddy run
  shell: /usr/bin/bash -e {0}
  env:
    SSH_AUTH_SOCK: /tmp/ssh-GLbX9AdHVKNp/agent.1757
    SSH_AGENT_PID: 1758
command-line line 0: keyword serveraliveinterval extra arguments at end of line
Error: Process completed with exit code 255.

Any help is much appreciated.

I tried putting the bash commands in single quotes, that works but isn't clean at all.

Share Improve this question edited Mar 24 at 12:55 The Dude asked Mar 24 at 12:48 The DudeThe Dude 12 bronze badges 5
  • 1 I doubt that you can run those extra commands inside ssh session like that. I'd make a actual shellscript that gets copied into remote shell and then execute it via ssh .. – rasjani Commented Mar 24 at 13:03
  • @rasjani I am trying it like that but it hangs I have a caddy run & command. Since it's a CD isn't it expected that I'd run commands like that? – The Dude Commented Mar 24 at 14:16
  • that deploy phase is essentially a bash script and you can't use commands even on plain old bash script like that. Either you put the commands you want to run as arguments to ssh or you make a separate script that does what you want on the host you are ssh'ing into .. – rasjani Commented Mar 24 at 14:19
  • @rasjani That's what I'm doing ssh -o ServerAliveInterval=600 -o StrictHostKeyChecking=no [email protected] 'sh myproject/scripts/deploy.sh but still caddy run & makes it hang and it never completes. – The Dude Commented Mar 24 at 14:32
  • Try github/appleboy/ssh-action. – Azeem Commented Mar 24 at 16:43
Add a comment  | 

1 Answer 1

Reset to default 0
- name: (Finally) Deploy to Hetzner
        run: |
          ssh -v ${{ secrets.SSH_OPTS }} ${{ secrets.HETZNER_USER }} "\
          cd myproject \
          git pull \
          npm ci \
          npm run build \
          npm run start \
          caddy run"

Might work.

本文标签: cicdGitHub action chaining multiple commands to SSHStack Overflow