I'm currently building a Bitbucket pipeline using pipeline variables so I can reuse the same pipeline across multiple projects. I have been unable to find how you use these variables in a SSH or SCP script within the pipeline. Below is an example.
Let's say I have the following three Deployment Variables in my Production Environment.
SERVER_IP => 192.168.10.21
SERVER_PORT => 1234
TEMP_DEPLOYMENT_LOCATION => my_temp_deployment_location
Now, let's say I would like to make a directory based on the above variables during the production deployment step in my bitbucket-pipelines.yml file. The SSH connection works, but the command to make the directory fails. It doesn't look like the variable is correctly evaluated.
ssh testuser@$SERVER_IP -p $SERVER_PORT 'mkdir -v ~/private/$TEMP_DEPLOYMENT_LOCATION/;'
Here is the log output by Bitbucket Pipeline when the above script is run.
+ ssh testuser@$SERVER_IP -p $SERVER_PORT 'mkdir -v ~/private/$TEMP_DEPLOYMENT_LOCATION/;'
mkdir: cannot create directory ‘~/private//’: File exists
What is the correct way to evaluate this pipeline variable in the above SSH command to create the following?
ssh testuser@192.168.10.21 -p 1234 'mkdir -v ~/private/my_temp_deployment_location/;'
Hi Rob,
At the moment, due to the way the quotes are set, the TEMP_DEPLOYMENT_ENVIRONMENT variable is trying to be retrieved inside of the remote machine, instead of from the pipelines environment.
To instead reference the environment variable from Pipelines, the correct way appears to be using double quotes to wrap the command.
See: https://stackoverflow.com/questions/3314660/passing-variables-in-remote-ssh-command
Thanks,
Phil
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.