Bitbucket Pipe for WP Engine Site Deployments

Tags:

Key Takeaways

  • Deploy WordPress code from Bitbucket to WP Engine using WP Engine Bitbucket Pipe. Options include deploying full site directory or sub-directory, custom rsync flags, and cache clearing. Utilizes WP Engine’s SSH Gateway for deployment.

  • Configuration requires saving private SSH Key to Bitbucket and public SSH Key to WP Engine. Set up bitbucket-pipelines.yml for deployment orchestration.

  • Create a bitbucket-pipelines.yml file in repo root for deployment configuration. Allows different workflows for various branches/environments.

  • Check out best practices for deploying with version control. Ensure files and directories are properly managed for deployment efficiency.

If you need to deploy WordPress® code from a Bitbucket repo to WP Engine, use our WP Engine Bitbucket Pipe.1 Deploy a full site directory or any sub-directory with the SRC_PATH and REMOTE_PATH options. Other options include custom rsync flags, or clearing cache.

This configuration uses WP Engine’s SSH Gateway, instead of WP Engine’s GitPush feature.

View the full guide on Bitbucket here.

The basic setup steps outlined below are:

  1. Generate an SSH key pair
  2. Add your SSH private key in Bitbucket
  3. Add your SSH public key in WP Engine
  4. Add a YAML config file

Follow the steps in our SSH gateway article to Generate a new SSH key.

Warning

SHA1 has been deprecated. When generating SSH keys for continuous integration, use ED25519 formatting instead.

  1. Add the Private key from the key pair you generated, to your Repository Variables or your Workspace variables.
    • Bitbucket requires base64 encoding to store keys. This guide will outline how to encode your generated key in the proper format.
    • Save the new secret “Name” as WPE_SSHG_KEY_PRIVATE.
Tip

If using a Bitbucket Workspace, adding the SSH key to the Workspace Variables will allow all repos to reference the same SSH key for deploys. The SSH Key also grants access to all installs made available to its WP Engine User. One key can then effectively be used to deploy all projects to their respective sites on WP Engine.

Add the Public key from the key pair you generated, to your SSH Keys in the WP Engine User Portal. This Guide will show you how.

  1. Create a bitbucket-pipelines.yml file in the root of your repo locally. Copy and paste the configuration from below, replacing the value under branches: and the value for WPE_ENV:

To deploy from another branch, simply create another yml file locally for that branch and replace the values for branches: and WPE_ENV: for that workflow.

After you’ve added you YAML file, Git push to your site’s Bitbucket repo. The pipeline will do the rest!

View your pipelines progress and logs by navigating to the “Pipelines” tab in your repository.

Copy and paste a configuration from below, replacing the value under branches: and the value for WPE_ENV:

pipelines:
  branches:
    main:
      - step:
          name: Deploy to Production
          script:
          - pipe: wpengine/wpe-site-deploy:v2
            variables:
              WPE_SSHG_KEY_PRIVATE: $WPE_SSHG_KEY_PRIVATE
              WPE_ENV: '<sitename>'
pipelines:
  branches:
    main:
      - step:
          name: Deploy to Production
          script:
          - pipe: wpengine/wpe-site-deploy:v2
            variables:
              WPE_SSHG_KEY_PRIVATE: $WPE_SSHG_KEY_PRIVATE
              WPE_ENV: '<sitename>'
    staging:
      - step:
          name: Deploy to Staging
          deployment: staging
          script:
          - pipe: wpengine/wpe-site-deploy:v2
            variables:
              WPE_SSHG_KEY_PRIVATE: $WPE_SSHG_KEY_PRIVATE
              WPE_ENV: '<sitename>'

Required:

NameTypeUsage
WPE_SSHG_KEY_PRIVATEsecretsBase64 encoded Private SSH Key for the SSH Gateway and deployment. See below for SSH key usage.

Deploy Options:

NameTypeUsage
WPE_ENVstringInsert the name of the WP Engine environment you want to deploy to.
SRC_PATHstringOptional path to specify a directory within the repo to deploy from. Ex. wp-content/themes/genesis-child-theme/ Defaults to root of repo filesystem as source.
REMOTE_PATHstringOptional path to specify a directory destination to deploy to. Ex. wp-content/themes/genesis-child-theme/ Defaults to WordPress root directory on WP Engine.
FLAGSstringSet optional rsync flags such as --delete or --exclude-from This pipe defaults to a non-destructive deploy using the flags -azvr --inplace --exclude=".*"
Caution: Setting custom rsync flags replaces the default flags provided by this pipe. Consider also adding the -azvr flags as needed.
-a preserves symbolic links, timestamps, user permissions and ownership.
-z is for compression
-v is for verbose output
-r is for recursive directory scanning
SCRIPTstringRemote bash file to execute post-deploy. This can include WP_CLI commands for example. Path is relative to the WP root and file executes on remote. This file can be included in your repo, or be a persistent file that lives on your server.
CACHE_CLEARboolOptionally clear page and CDN cache post deploy. This takes a few seconds. Default is TRUE
Information

As this script does not restrict files or directories that can be deployed, it is recommended to leverage WP Engine’s starter .gitignore template.

NEXT STEP: Check out our best practices for deploying when using version control