Bitbucket “rsync” pipelines

The rsync pipelines use the logic of “push everything that is found in the repo and delete any files that do not exist”. Even though it will keep everything clean it might not be perfect for every implementation!

Why? I’ve come across many plugins & themes that are using their own folders to add files for CSS minification as an example. I don’t consider this good practice. It would be better if their authors chose to use either the wp-content or the uploads directory instead.

If you happen to know any of your themes or plugins to be doing this then preferably use the git-ftp pipeline instead or remove the --delete parameter from the rsync command even though that might eventually result in having extra particles in your folders.

The setup

Add a bitbucket-pipelines.xml to your repository with the following code:

pipelines:
  custom:
    production_manual:
      - step:
          script:
            - rsync -zrSlh -v --stats --progress --delete --exclude-from=excludes.txt $BITBUCKET_CLONE_DIR/themes/ [email protected]$PRODUCTION_HOST:$PRODUCTION_FOLDER/themes/
            - rsync -zrSlh -v --stats --progress --delete --exclude-from=excludes.txt $BITBUCKET_CLONE_DIR/plugins/ [email protected]$PRODUCTION_HOST:$PRODUCTION_FOLDER/plugins/
    staging_manual:
      - step:
          script:
            - rsync -zrSlh -v --stats --progress --delete --exclude-from=excludes.txt $BITBUCKET_CLONE_DIR/themes/ [email protected]$STAGING_HOST:$STAGING_FOLDER/themes/
            - rsync -zrSlh -v --stats --progress --delete --exclude-from=excludes.txt $BITBUCKET_CLONE_DIR/plugins/ [email protected]$STAGING_HOST:$STAGING_FOLDER/plugins/
  branches:
    production:
      - step:
          script:
            - rsync -zrSlh -v --stats --progress --delete --exclude-from=excludes.txt $BITBUCKET_CLONE_DIR/themes/ [email protected]$PRODUCTION_HOST:$PRODUCTION_FOLDER/themes/
            - rsync -zrSlh -v --stats --progress --delete --exclude-from=excludes.txt $BITBUCKET_CLONE_DIR/plugins/ [email protected]$PRODUCTION_HOST:$PRODUCTION_FOLDER/plugins/
    staging:
      - step:
          script:
            - rsync -zrSlh -v --stats --progress --delete --exclude-from=excludes.txt $BITBUCKET_CLONE_DIR/themes/ [email protected]$STAGING_HOST:$STAGING_FOLDER/themes/
            - rsync -zrSlh -v --stats --progress --delete --exclude-from=excludes.txt $BITBUCKET_CLONE_DIR/plugins/ [email protected]$STAGING_HOST:$STAGING_FOLDER/plugins/

The rsync command will also use an excludes.txt to exclude any files from being synced.

/.*
bitbucket-pipelines.yml
excludes.txt

You will have to add in your repository settings your SSH Key as well as the following Repository Variables:

  • PRODUCTION_SSH_USER
    the SSH username for the production environment (i.e. deployproduction).
  • PRODUCTION_HOST
    the host for the production environment (i.e. xkon.gr).
  • PRODUCTION_FOLDER
    the wp-content directory path for your production environment without a trailing slash (i.e. site/public_html/wp-content).
  • STAGING_SSH_USER
    the SSH username for the staging environment (i.e. deploystaging).
  • STAGING_HOST
    the host for the production environment (i.e. staging.xkon.gr).
  • STAGING_FOLDER
    the wp-content directory path for your staging environment without a trailing slash (i.e. staging/public_html/wp-content).