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;
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
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).
Oh, I see now, I think I will do something like that so, thanks!
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.
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.
Hi,
found a solution that worked for me here by julien amblard:
https://community.atlassian.com/t5/Bitbucket-questions/how-bitbucket-listen-a-bash-script-execution-end/qaq-p/737327
Helped me to come up with this solution for the deployment of craftcms site:
image: php:7.2-clipipelines: 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
It looks like you're new here. Sign in or register to get started.