AutoDeploy executes each deployment step in a separate SSH session. This means that if you need to SSH to another server and run commands there, you need to structure your commands appropriately.
When you have steps like:
ssh tis-staging-apibash updateStaging.sh
The second command runs on the original server, not on tis-staging-api, because the SSH session from step 1 is closed after execution.
Combine the SSH and the command into a single step:
ssh tis-staging-api 'cd /path/to/project && bash updateStaging.sh'Or if you need to pass environment variables:
ssh tis-staging-api 'cd /path/to/project && export VAR=value && bash updateStaging.sh'Create a script on your jump server that handles the nested deployment:
On your jump server, create deploy-api.sh:
#!/bin/bash
ssh tis-staging-api << 'EOF'
cd /path/to/project
bash updateStaging.sh
EOFThen in AutoDeploy, just run:
bash deploy-api.shConfigure your SSH to automatically jump through the first server.
In your local ~/.ssh/config:
Host staging-jump
HostName your-jump-server.com
User your-username
IdentityFile /path/to/key.pem
Host tis-staging-api
HostName internal-api-server
User api-user
ProxyJump staging-jump
Then you can directly SSH to the final server in AutoDeploy's configuration.
If you need to use your SSH keys on the jump server:
- Enable SSH agent forwarding in your AutoDeploy SSH configuration
- Use a single command:
ssh -A tis-staging-api 'bash updateStaging.sh'
For a monorepo sub-deployment that needs nested SSH:
Deployment Steps:
- Name: Deploy to API Server
Command:
ssh tis-staging-api 'cd /var/www/api && git pull && npm install && pm2 restart api'Working Directory:.
Or with a deployment script:
- Name: Run Deployment Script
Command:
bash scripts/deploy-to-api.shWorking Directory:.
- Use SSH keys on the jump server for passwordless authentication to the final server
- Test your SSH chain manually before configuring in AutoDeploy
- Use absolute paths in your commands since the working directory might be different
- Add error handling to your scripts to catch connection failures
If your deployment hangs:
- The SSH command might be waiting for a password (use SSH keys instead)
- The nested SSH might be waiting for host key verification (add
-o StrictHostKeyChecking=nofor known hosts) - Check if the command needs a TTY (add
-tflag to ssh command)