follow this guide https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/
or
ssh-keygen
eval $(ssh-agent)
ssh-add ~/.ssh/<private_key_file>
Go to Bitbucket -> repo -> repo-setting-> -> Pipelines -> Settings Enable pipeline
Go to Bitbucket -> repo -> repo-setting-> Access Keys -> Add Key
copy public key
cat ~/.ssh/id_rsa.pub
ssh -T [email protected]
The command message tells you which of your Bitbucket accounts can log in with that key.
If there any issues run below command (Permission denied (publickey))
ssh-add -l
ssh-add ~/.ssh/<private_key_file>
Go to Bitbucket -> repo -> repo-setting-> Access Keys -> Known hosts Add IP address of the server and click on Fetch and Add Host
=============================================================
Go to project directory
git remote -v
set ssh format url
git remote set-url origin [email protected]:<workspace_ID>/<repo_name>.git
=============================================================
Go to Bitbucket -> repo -> repo-setting-> -> Pipelines -> Repository variables Name: SSH_USER Value : centos (server username) Name: PORT Value: 22 Name:SERVER Value: IP address untick secured
===============================================================
Go to Bitbucket -> repo -> repo-setting-> -> Pipelines -> SSH Keys Click on Generate keys Copy public key to ~/.ssh/authorized_keys on the remote host (login to server and go to above path and edit file with nano and paste the public key in new line)
===============================================================
# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: php:7.1.29
pipelines:
branches:
production:
- step:
name: Deploy to production
deployment: production
script:
- echo "Deploying to production environment"
- pipe: atlassian/ssh-run:0.2.2
variables:
SSH_USER: $SSH_USER
SERVER: $SERVER
#SSH_KEY: $MYKEY
PORT: $PORT
COMMAND: "/var/folder-name/deploy.sh" ```
===============================================================
Note:
for centos
#!/bin/sh
for ubuntu
#!/bin/bash
Bash path must be same than results of: $ which bash
#!/bin/sh
repos=(
"/var/www/project1"
"/var/www/project2"
)
echo ""
echo "Getting latest for" ${#repos[@]} "repositories using pull"
for repo in "${repos[@]}"
do
echo ""
echo "****** Getting latest for" ${repo} "******"
cd "${repo}"
git pull
echo "******************************************"
done