Simple Bitbucket Piplelines script

Use a quick script to get you up and running with Bitbucket Pipelines

When you start integrating version control into your process of deployment you will inevitably need something like Bitbucket Pipelines.

I am in no way an expert on Bitbucket / Git, but here is how I setup my own deployment.

First you will need to initialize the deployment.

You will need to setup your Repository Variables so that your bitbucket-pipelines.yml can use them when deploying your websites.

Go to: Settings – > Pipelines -> Repository Variables

Then setup your variables FTP_USERNAME and FTP_PASSWORD. You will need to make sure to encrypt your FTP_PASSWORD in case there is somebody else working with you on this repository.

WARNING: when you run git ftp init it will wipe out everything you have on your production server. I recommend making sure you have backups before you do your first init.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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: samueldebruyn/debian-git

pipelines:
branches:
master:
- step:
script:
- apt-get update
- apt-get -qq install git-ftp
- git ftp init --user $FTP_USERNAME --passwd $FTP_PASSWORD sftp://1.1.1.1/home/user/public_html

Then you will need to change your bitbucket-pipelines.yml to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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: samueldebruyn/debian-git

pipelines:
branches:
master:
- step:
script:
- apt-get update
- apt-get -qq install git-ftp
- git ftp push --user $FTP_USERNAME --passwd $FTP_PASSWORD sftp://1.1.1.1/home/user/public_html

This will push changed code instead of the whole repository.

Leave a Reply