Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 to your repo
# 3. From Bitbucket Cloud > Commits > Commit Number > Run Pipeline > Custom:Init (this will
# push everything and initial GitFTP)
#
# Usage ---
# - On each commit to master branch, it'll push all files to the $FTP_HOST
# - You also have the option to 'init' (from Bitbucket Cloud) - pushes everything and initialises
# - Finally you can also 'deploy-all' (from Bitbucket Cloud) - if multiple deploys fail, you
# can deploy everything to "catch up"
#
image: aariacarterweir/lamp-gitftp: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
@JustEugen

This comment has been minimized.

Copy link

commented Feb 2, 2018

Thank you for this

@Kaapiii

This comment has been minimized.

Copy link

commented Jun 6, 2018

Thanks, the custom steps are nice.
If anyone faces the issue that the pipeline fails with the message:

  • apt-get update
    bash: apt-get: command not found

Then you probably used a reserved word in your environement variables.

@zanstro

This comment has been minimized.

Copy link

commented Jul 4, 2018

Thanks, that's helpful.
Is there any modification that can be made to include a staging deployment alongside the production deployment? It would be useful to utilize two branches, one for staging deployment (branch name: staging) and one for production deployment (branch name: master). Once we push to staging branch, the code is deployed to the staging server and correspondingly with the production.

@goatfryed

This comment has been minimized.

Copy link

commented Jul 26, 2018

@dryokolaptis If you want to make a staging deployment, add

develop: # -- When committing to developbranch
    - step:
        script:
          - npm install
          - git ftp push -u "$FTP_DEV_USERNAME" -p "$FTP_DEV_PASSWORD" ftp://$FTP_DEV_HOST

to your branches definition along with additional env vars.

@goatfryed

This comment has been minimized.

Copy link

commented Jul 26, 2018

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

@mcnamee

This comment has been minimized.

Copy link
Owner Author

commented Aug 19, 2018

Hi @goatfryed
Take a look at https://github.com/git-ftp/git-ftp/blob/master/man/git-ftp.1.md#syncing-untracked-files

Essentially you can add files/directories to .git-ftp-include

@Mochnant

This comment has been minimized.

Copy link

commented Aug 29, 2018

Thanks for the sample. I'm trying to make it work with sftp, but it fails with this message:

curl: (1) Protocol sftp not supported or disabled in libcurl

Is there something I can do to fix this? Thanks.

@Mochnant

This comment has been minimized.

Copy link

commented Aug 29, 2018

I fixed the error by switching to a different Docker image:

image: madshansen/docker-git-ftp:latest

@FDiskas

This comment has been minimized.

Copy link

commented Nov 16, 2018

please update node version to latest lts version

@iconifyit

This comment has been minimized.

Copy link

commented Jan 28, 2019

I get an error saying no package.json is found in the current directory. Are there some preliminary steps that must be taken in order to use this? My code that is being deployed does not use any packages. Just vanilla HTML & PHP code.

@fu-sen

This comment has been minimized.

Copy link

commented Feb 15, 2019

@iconifyit I also encountered the same problem. package.json is used with npm install.
Therefore, deleting the 3 lines:

          - npm install

After this fix, you get the expected behavior.

@edyrkaj

This comment has been minimized.

Copy link

commented Feb 22, 2019

hi,
How to push only /dist folder after running npm scripts commands.
Thank you

@mahammedzkhan

This comment has been minimized.

Copy link

commented Mar 5, 2019

This doesn't work, it gives errors when trying to initialize the repo because of the FTP_URL.

@AhmedCommando

This comment has been minimized.

Copy link

commented Mar 8, 2019

hi,
How to push only /dist folder after running npm scripts commands.
Thank you

any luck?

@ezvr

This comment has been minimized.

Copy link

commented Mar 12, 2019

i also want to know this. also i'd like to know how to push to a specific ftp folder

@shaneseaton

This comment has been minimized.

Copy link

commented Mar 29, 2019

For anyone else struggling with this, I put my env vars in the settings > deployments > production area. This meant that for the init to work correctly, I had to add the 'deployment: production' line to each of the steps that wanted access to those vars.

e.g

  custom: 
    init: 
    - step:
        deployment: production
        script:
          - git ftp init -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST
    deploy-all: 
    - step:
        deployment: production
        script:
          - git ftp push -u "$FTP_USERNAME" -p "$FTP_PASSWORD" ftp://$FTP_HOST --all

Hope that saves anyone else some confusion.

@thorst

This comment has been minimized.

Copy link

commented Jul 11, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.