Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

how bitbucket listen a bash script execution end ?

Julien Amblard February 26, 2018

Hello,

I'm using bitbucket pipeline for deploying my application on my server.

In my pipeline script i connect on my server with ssh and run a bash script on it, 

Everything look's to be ok, but after the bash script exit (with a 0, cause of success), nothing happens, the pipeline keep "processed", doing nothing,  instead of ending with a success.

 

What i missing ? how the pipeline script can catch the end of the bash script ?

 

Here is my pipeline script : 

image: samueldebruyn/debian-git
pipelines: branches: develop:
- step: caches:
- node script:
- apt-get update
- apt-get install -y unzip
- apt-get -qq install git-ftp
- git ftp push --user $FTP_USERNAME --passwd $FTP_PASSWORD $FTP_HOST_DEV
- ssh -tt $SSH_HOST 'bash -s' < deploy.bash

 

Here is my bash script :

#!/bin/bashcd 
/path/to/my/folder
npm install
pm2 restart developement
exit $?

 

thank you !

 (sorry for my english)

1 answer

1 accepted

0 votes
Answer accepted
Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 26, 2018

Try dropping the < in your ssh call

ssh -tt $SSH_HOST 'bash -s' < deploy.bash

ssh -tt $SSH_HOST deploy.bash 

Julien Amblard February 26, 2018

Hello,

i've tried  

ssh -tt 'bash -s' $SSH_HOST deploy.bash 

same issue, the difference is, the console don't return anything of what happened on the server, but keep runing forever

 

and i've tried 

ssh -tt $SSH_HOST deploy.bash 

he throw me an error : 

+ ssh -tt $SSH_HOST deploy.bash 
bash: deploy.bash: command not found
Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 26, 2018

Is the script located on the target server?

 

If not, you can try running it as such

 

ssh $SSH_HOST << EOF

npm install

pm2 restart development

EOF

Julien Amblard February 26, 2018

it drive me crazy

still have the same issue, he keep runing on the last command, "EOF".

ssh is ok, cd, nmp install, and pm2 are ok too, but he process forever on the last command "EOF"

i really don't get it

Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 26, 2018

The EOF just creates a section where you can send multiple commands to the server, so that shouldn't cause any problems.

Can you access the server directly and run each command in turn to see if one is causing an issue?

Julien Amblard February 26, 2018

ok so, i juste add an exit $? before de last EOF and it work

 

here is the code : 

image: samueldebruyn/debian-git
pipelines:
branches:
develop:
- step:
caches:
- node
script:
- apt-get update
- apt-get install -y unzip
- apt-get -qq install git-ftp
- git ftp push --user $FTP_USERNAME --passwd $FTP_PASSWORD $FTP_HOST_DEV
- ssh -tt $SSH_HOST << EOF
- cd $FTP_HOST_DEV
- npm install
- pm2 restart developement
- exit $?
- EOF

so, thank you !

you save my night, i can sleep in peace now

Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 26, 2018

Glad to help

Julien Amblard February 26, 2018

i just realise he stop at the exit, so he don't run the last EOF, i'm not really sur if it's a problem or not...

by the way, when i run every command on my server, everything work correctly. 

Steve Thornhill
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 26, 2018

Just to clarify, where you have the two EOF in the command file it is acting as a script wrapper, so each line in between the EOFs is run (not the actual EOF itself)

Similar to a do loop.

Julien Amblard February 26, 2018

ok i get it now, so thank you !

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events