Skip to content

Instantly share code, notes, and snippets.

@mcnamee
Last active December 14, 2023 03:57
Show Gist options
  • Save mcnamee/aa141afde5c0359c568c169a56f100d7 to your computer and use it in GitHub Desktop.
Save mcnamee/aa141afde5c0359c568c169a56f100d7 to your computer and use it in GitHub Desktop.
Bitbucket Pipelines - Deploy via FTP to shared hosting
# Installation ---
# 1. In Bitbucket, add FTP_USERNAME, FTP_PASSWORD and FTP_HOST as environment variables.
# 2. Commit this file (bitbucket-pipelines.yml) to your repo (in the repo root dir)
# 3. From Bitbucket Cloud > Commits > Commit Number > Run Pipeline > Custom:Init (this will
# push everything and initialize GitFTP)
#
# Usage ---
# - On each commit to master branch, it'll push all files to the $FTP_HOST
# - You also have the option to 'init' (see 'Installation' above) - pushes everything and initialises
# - Finally you can also 'deploy-all' (from Bitbucket Cloud > Commits > Commit Number > Run Pipeline > Custom:deploy-all)
# if multiple deploys fail, you can deploy everything to "catch up"
#
image: wearepvtl/bitbucket-pipelines-git-ftp:latest
pipelines:
custom: # Pipelines that are triggered manually via the Bitbucket GUI
init: # -- First time init
- step:
caches:
- node
- composer
script:
- npm install
- git ftp init -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST
deploy-all: # -- Deploys all files from the selected commit
- step:
caches:
- node
- composer
script:
- npm install
- git ftp push -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST --all
branches: # Automated triggers on commits to branches
master: # -- When committing to master branch
- step:
deployment: production
caches:
- node
- composer
script:
- npm install
- git ftp push -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST
@thorst
Copy link

thorst commented Jul 11, 2019

If you need to deploy to a sub-directory (such as htdocs) include the full path as your ftp host.

@makeitTim
Copy link

Should be able to sync just a sub-folder as if it were root like this:

git ftp push --syncroot dist/ -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST

However, none of this is working for me. Bitbucket doesn't think git ftp exists:

+ git ftp push --syncroot as/ -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST
git: 'ftp' is not a git command. See 'git --help'.

@makeitTim
Copy link

makeitTim commented Nov 28, 2019

Already fixed git: 'ftp' is not a git command. I had commented out image: aariacarterweir/lamp-gitftp:latest because it looked like specific to somebody else's environment stack, but it is needed.

This works awesomely! Thanks.

@JosepRoo
Copy link

Question: If I put node_modules and public/dist on git ignore, i assume the git ftp push will ignore these folders, even if i do npm install and some npm run build.
Is there a way to force git ftp push to also push some ignored files or is there another workaround?

My approach would be to cache the ignored directories, then after install and build use some combination of find and basic ftp

Force the add on that folder and the commit it
script:
- npm install
- git add --force dist
- git commit -m "Build"
- git ftp push --syncroot dist -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST

@thorst
Copy link

thorst commented Dec 5, 2020

This started failing last night, docker image no longer there, but execution was much faster than bitbuckets normal image

@mcnamee
Copy link
Author

mcnamee commented Dec 6, 2020

Hi @thorst - thanks for letting me know. I've setup a new Docker image and updated the script above.
Simply update the reference image to image: wearepvtl/bitbucket-pipelines-git-ftp:latest (from image: aariacarterweir/lamp-gitftp:latest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment