To create the pipeline for bitbucket, we need two files i.e deploy.sh(can create for staging and production) and bitbucket.pipeline.yml in our application.
Make a directory called deployment and create the sub directory for stage and production and added the file deploy.sh inside the sub directory in our application as below:
To create the bitbucket.pipeline.yml , the file is provided by the bitbucket just we need to commit that file from the bitbucket and we can add required process to deploy through the pipeline.Here how the bitbucket.pipeline.yml looks like :
After that go to the bitbucket, and go to the repository setting and click SSH keys option and it will show like this :
Here the SSH public key already generated(if not you can generate), so we need to copy that public key and need to add this key in the server in the directory called ssh/authorized_keys, So below the command to add the ssh pub key to the server using vim :-
vim ~/.ssh/authorized_keys
Click Shift + i to insert.
Right click and paste the copied SSH pub key.
After adding the public key in the server, we need to add the fingerprint in the bitbucket for the server.To do that
Go to the Repository settings and click the SSH keys.
You will see the known hosts with the input field i.e host address and the button called fetch
Add the ip of the server in the host address and click fetch.
After adding the ssh key to the server, you need to go the deployment in the bitbucket and add the environment which will look like this :
So in the bitbucket.pipeline.yml you need to define the environment you want to deploy as shown in the figure :
Now, your application is ready for deployment through bitbucket.