What is BitBucket?
Bitbucket Pipeline is an integrated CI/CD service, built into Bitbucket. It allows you to automatically build, test, and even deploy your code, based on a configuration file in your repository.
Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day.
Continuous Delivery (CD) is a natural expansion of Continuous Integration: a methodology wherein developers guarantee that each change to the code is releasable and that we can release any version at push of a button.
Continuous Delivery means to make releases tedious, so we can convey every now and again and get quick feedback for what clients care about.
At the center of Pipelines is the bitbucket-pipelines.yml file. It defines all your build configurations (pipelines) and needs to be created in the root of your repository. With ‘configuration as code’, your bitbucket-pipelines.yml is versioned along with all the other files in your repository and can be edited in your IDE.
There are configuration parameters for Bitbucket-pipelines.yml but below are required.
- Pipelines: mark the beginning of all pipeline definitions.
- Default: contains the steps that will run on every push.
- Step: each step starts a new Docker container that includes a clone of your repository, and then runs the contents of your script section inside it.
- Script: a list of commands that are executed in sequence.
Enable Bitbucket Pipelines
The first thing you need to do is to enable Bitbucket Pipelines for your project. This has to be done for every project where you want to use Pipelines. Go to the left column and open up “Pipelines”.
Bitbucket helps us out here and shows a 3-step process to enable and configure your pipeline:
- Enable the pipelines
- Copy the sample configuration to your clipboard
- Click on the “create bitbucket-pipelines.yml” button
Configuration file for FTP deployments
To deploy a website to an FTP server, I use git-ftp. It’s a wonderful tool that allows you to upload only changed or removed files to an FTP server.
Therefore, we need to modify two parts of the Pipelines configuration file. We need to choose the Docker image so that Debian-git can be used because it has git already installed.
Here is my full bitbucket-pipelines.yml file for FTP deployments. Here, we have used Repository Variables to store FTP credentials.
– apt-get update
– apt-get -qq install git-ftp
– git ftp push –user $FTP_USER_NAME –passwd $FTP_PASSWORD ftp://YOUR_SERVER_ADDRESS/PATH_TO_WEBSITE/
Setup Repository Variables
Storing sensitive information in the configuration file is not the right approach. so, we will store all our confidential information outside the configuration file We will store out FTP credentials in Repository Variables also can store credentials in encrypted format for more secure.
- Go to the Settings of your repository
- Open the “Repository Variables” page under the Pipelines section.
Here you can define Repository variables that will be accessible from your scripts when a new build is triggered.
For FTP you should define these two variables:
Triggering a build
Triggering a build is as easy as making a commit to your git repository. After each commit, Bitbucket will run through all the steps that you’ve defined in bitbucket-pipelines.yml. You can see the status of your builds at any time by going to the Pipelines section.
Bitbucket is a great service for CI/CD, also can configure with AWS S3 bucket, also you can set automatic and manual deployment, and notifying all activity by email.
Latest posts by Anish Bhut (see all)
- Bit Bucket Pipeline - July 16, 2019
- Step-by-Step Guide to Manage Cloud Printing: Google Cloud Print using API - May 17, 2019