Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×My bitbucket-pipelines.yml file looks like this https://pastebin.com/MX5bXiuB
As one can see, in my bitbucket-pipelines.yml I use some Deployment variables, such as $SSH_USER, $SSH_HOST etc.
And my question is about that test-deploy.sh that I use to run some commands on my remote server during deploy process. I'd like to use that (or some other) pipelines Deployment variables (like $DEPLOY_DIR etc.) inside my test-deploy.sh so i could rule them all in one place. When I try
cd $DEPLOY_DIR
inside my test-deploy.sh it does not work. Neither work
- cat ./_ci/test-deploy.sh $DEPLOY_DIR | ssh -T $SSH_USER@$SSH_HOST
followed by
cd $1
Any ideas of how this could be done are appreciated.
Hi @vabard
This is not a problem with Pipelines environment, but a bash evaluation issue.
You are trying to send variables that are not evaluated to an SSH command.
The cat command will send the text inside the test-deploy.sh file. They are not variables until a terminal try to read them. The remote receiving them will not be able to interpret them because the variables are not declared there.
Also, the command below is not correct.
- cat ./_ci/test-deploy.sh $DEPLOY_DIR | ssh -T $SSH_USER@$SSH_HOST
cat will just list the content of files, and in this case the $DEPLOY_DIR is not a file probably.
Suggestion
Can you try instead:
- eval ssh -T $SSH_USER@$SSH_HOST \"$(cat ./_ci/test-deploy.sh | tr '\n' ';')\"
Explanation:
command1;command2 $VARIABLE;command3
"command1;command2 $VARIABLE;command3"This will make the ssh command understand all of those commands as an argument.
ssh -T $SSH_USER@$SSH_HOST "command1; command2 variable_value; command3"
You may find easier ways to solve this problem, this is just the solution I could implement now. I hope it helps.
Keep in mind that every time you mention a local variable in a script that will be sent to a remote host, you need to evaluate that variable before sending the content to the remote host.
Thank you @Daniel Santos , your snippet worked like a charm!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome! =]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.