Hi there,
I am trying to figure out how to write down multiple SSH commands on the remote server. For now I created environment variables to make it less painfull to do a ssh login per command, but I prefer to open one SSH connection and then execute all the commands (more efficient).
My only working solution now is to create separate lines with SSH login and commands:
- ssh $DEPLOY_USER@$DEPLOY_SERVER tar -xzf $DEPLOY_PATH/deployarchive.tar.gz --directory="$DEPLOY_PATH/folder"
- ssh $DEPLOY_USER@$DEPLOY_SERVER wget --cache=off --output-document $DEPLOY_PATH/deploy.sh https://a-file-on-the-internet.sh
- ssh $DEPLOY_USER@$DEPLOY_SERVER 'tar -xzf $DEPLOY_PATH/deployarchive.tar.gz --directory="$DEPLOY_PATH/folder"; wget --cache=off --output-document $DEPLOY_PATH/deploy.sh https://a-file-on-the-internet.sh;'
- ssh $DEPLOY_USER@$DEPLOY_SERVER << EOF tar -xzf $DEPLOY_PATH/deploy.tar.gz --directory="$DEPLOY_PATH/folder"; wget --cache=off --output-document $DEPLOY_PATH/deploy.sh https://a-file-on-the-internet.sh; EOF;
Hi,
found a solution that worked for me here by julien amblard:
Helped me to come up with this solution for the deployment of craftcms site:
image: php:7.2-cli
pipelines:
branches:
dev:
- step:
script:
- apt-get update
- apt-get install -y ssh
- ssh -tt $DEV_USER_AND_SERVER << EOF
- cd $DEV_DIR;
- git config core.sparseCheckout true
- echo "*" > .git/info/sparse-checkout;
- echo "!storage" >> .git/info/sparse-checkout;
- echo "!public/build" >> .git/info/sparse-checkout;
- git add .;
- git reset --hard origin/dev;
- git pull;
- rm -f .env;
- mv .env.vs1010 .env;
- rm web/.htaccess;
- mv web/.htaccessVs1010 web/.htaccess;
- COMPOSER=composer.json php72 composer.phar install --no-interaction --prefer-dist --optimize-autoloader;
- COMPOSER=composer.json php72 composer.phar dump-autoload --classmap-authoritative;
- ./craft cache/flush-all;
- ./craft migrate/all;
- ./craft project-config/sync;
- exit $?
- EOF
Still no answer for this one? I would also like to use multiple commands in one SSH connection and not use deploy script, as inside of it I have some variables that i would like to use from bitbucket.
If i use deploy script it does not pick up variables from bitbucket.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
FYI this worked for me:
Example:
ssh $DEPLOY_USER@$DEPLOY_SERVER "command1; command2; if [ $? -ne 0 ]; then echo 'Failed'; exit 1; fi;"
Using "" outside and '' inside.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Didn't you have any reply on this topic? I am trying to do the same, but I need all the commands to run in the same ssh connection :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, not yet. We just did a line by line execution. To run all commands in the same SSH connection we ended up by executing a remote .sh script (download and run, see my example with wget).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, I see now, I think I will do something like that so, thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.