Deploying to WPEngine from Azure DevOps

I recently needed to deploy some code from Azure DevOps to WPEngine. There are plenty of ways to deploy code to WPEngine, this is what worked for me.

Create a Pipeline

First set up a pipeline to create an artifact with all the files that need to be deployed. Run any frontend builds in the pipeline before creating the artifact if necessary.

Here’s a basic pipeline to take all the files in the source directory, where the source directory is the base directory of a custom theme.

trigger:
 - develop
 - stage
 - main

pool:
 vmImage: 'ubuntu-latest'

steps:
 - task: PublishPipelineArtifact@1
inputs:
    targetPath: "$(Build.SourcesDirectory)"
    artifact: client_theme

The targetPath is the root directory of repo. This one publishes the entire dir (which happens to be a WordPress theme dir) as an artifact. Then it can be used in a release pipeline to send to WPEngine. The release pipeline will then use a script which will sync all the files from the artifact to WPEngine utilizing RSYNC.

Create a Release Pipeline

After setting up pipeline and running once, should be able to add Artifact.

Add Artifact

Enable Continuous deployment

Enable Continuous Deployment

Create a stage for each environment and use artifact filters to trigger based on branch:

Enable Continuous Deployment

Artifact filter based on Git branch

Artifact Filters

Add Install SSH Key and Bash Script tasks:

Configure SSH

Add Hosts Entry (see below), SSH Public key, and SSH Key. Also make sure Advanced ‘Add entry to SSH config’ selected and fill out Alias, Host name and User with correct wpengine info.

Use ssh-keyscan to get fingerprint

ssh-keyscan -H 192.168.1.162 >> ~/.ssh/known_hosts

Run a bash script, either inline or from file*:

Configure Script

#SSH Key Vars
SSH_PATH="$HOME/.ssh"
KNOWN_HOSTS_PATH="$SSH_PATH/known_hosts"


#Deploy Vars
WPE_SSH_HOST="$WPE_ENV_NAME.ssh.wpengine.net"
if [ -n "$DEST_PATH" ]; then
DIR_PATH="$DEST_PATH"
else
DIR_PATH=""
fi


if [ -n "$SRC_PATH" ]; then
SRC_PATH="$SRC_PATH"
else
SRC_PATH="."
fi


# Set up our user and path


WPE_SSH_USER="$WPE_ENV_NAME"@"$WPE_SSH_HOST"
WPE_DESTINATION="$WPE_SSH_USER":sites/"$WPE_ENV_NAME"/"$DIR_PATH"


# Setup our SSH Connection & use keys
mkdir "$SSH_PATH"
ssh-keyscan -t rsa "$WPE_SSH_HOST" >> "$KNOWN_HOSTS_PATH"


#Set Key Perms
chmod 700 "$SSH_PATH"
chmod 644 "$KNOWN_HOSTS_PATH"


# Deploy via SSH
rsync --rsh="ssh -v -p 22 -o StrictHostKeyChecking=no" -a --inplace --out-format="%n"  --exclude=".*" --exclude="node_modules" $SRC_PATH "$WPE_DESTINATION"

*Note - This script was derived from another source awhile back which I can’t seem to find.