BitBucket Pipeline - Build and deploy using node / gulp / git ftp

Viewed 2115

I noticed yesterday that BitBucket supported CICD pipelines, which is an amazing feature I'm eager to use.

I have however some difficulty setting it up.

My building process in general:

  • npm install
  • npm install -g bower
  • bower install
  • npm install -g gulp
  • gulp

The gulp command is building the HTML application and places the output to a build folder. After the build has been completed, I'd like the code to be transfered to a directory on my website.

This translates to the following bitbucket.yml:

# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN 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: node:6.9.4

pipelines:
  default:
    - step:
        caches:
          - node
        script: # Modify the commands below to build your repository.
          - npm install
          - npm install -g bower
          - bower install --allow-root
          - npm install -g gulp
          - gulp
          - cd build
          - apt-get update
          - apt-get -qq install git-ftp
          - git ftp init --user $FTP_USERNAME --passwd $FTP_PASSWORD ftp://mywebsite.com/public_html/mydirectory

The issue I'm getting is that the git ftp init seems to be uploading the src folder, and not the contents of the build one which is created during the gulp step.

Any ideas?


Update: --syncroot does seem to be a partial fix. Meaning it does try to upload the build directory now. However, the problem at this point is that git ftp only seems to be syncing tracked files.

Because the files in the build folder are created during the pipeline build, that does not apply to those.

I have tried to add a file named .git-ftp-include, which as described should transfer untracked files. Sadly, I haven't been successful in deploying my code.

.git-ftp-include file contents: build/index.html:/src/index.html

Which basically says: upload index.html from the build syncroot whenever the index.html in the src directory is changed.

2 Answers

In this case I recommend that you use ncftp. In the Pipelines will be something like:

- apt-get -qq install ncftp
- ncftpput -v -u "$FTP_USERNAME" -p "$FTP_PASSWORD" -R $FTP_HOST /remote build/*
Related