Continuous Integration with Azure DevOps

Pipelines is a feature of Azure DevOps by Microsoft that allows you to continuously integrate and deploy your code from your local machine to a Git repository.


Configure WP Engine

To connect the Azure pipeline to WP Engine, you’ll first need to add an SSH key to our Git service.

  1. Make sure you have an SSH Key ready to add to your site
  2. Log in to WP Engine User Portal
  3. Select the environment name
  4. Click on Git Push
  5. Add your Developer name and SSH Public Key
  6. Click Add Developer
  7. On the right side of this page, locate the Production Git remote url. It should look something like this [email protected]:production/mysitename.git

Repeat this process if you also wish to use a Staging or Development site, noting their Production Git remote URLs as well.

NOTE: Only if you wish to connect to legacy staging will you use the Staging Git remote URL instead. [email protected]:staging/mysitename.git


Create Your YAML Pipeline Files

  1. Create a file called azure-pipelines.yml in the root of your repository with the following code:
trigger:
- deploy/production
- deploy/staging
- deploy/development

pool:
  vmImage: 'ubuntu-latest'

extends:
  template: wpengine-pipeline.template.yml
  parameters:
    gitEmail: '[email protected]'
    gitUser: 'Your Name'
    productionGit: '[email protected]:production/yourprodsite.git'
    productionBranch: 'deploy/production'
    stagingGit: '[email protected]:production/yourstagingsite.git'
    stagingBranch: 'deploy/staging'
    developmentGit: '[email protected]:production/yourdevsite.git'
    developmentBranch: 'deploy/development'
    
  1. Replace the parameters in this file with values from your site, such as the branches you want the pipeline to run on, your email, your name, and the Git remote URLs that we noted from the section above.
  2. Create a file called wpengine-pipeline.template.yml in the root of your repository with the following code:
variables:
- group: ssh-info
- name: phpVersion
  value: 7.2

parameters:
- name: gitEmail
  type: string
  default: ''
- name: gitUser
  type: string
  default: ''
- name: productionGit
  type: string
  default: ''
- name: productionBranch
  type: string
  default: 'deploy/production'
- name: stagingGit
  type: string
  default: ''
- name: stagingBranch
  type: string
  default: 'deploy/staging'
- name: developmentGit
  type: string
  default: ''
- name: developmentBranch
  type: string
  default: 'deploy/development'

steps:
- checkout: self
  persistCredentials: true

- task: [email protected]
  inputs:
    knownHostsEntry: '$(knownHostsEntry)'
    sshPublicKey: '$(sshPublicKey)'
    sshKeySecureFile: 'id_rsa_azure'

- task: [email protected]
  condition: and(eq(variables['build.sourceBranch'], 'refs/heads/${{ parameters.productionBranch }}'), ne('${{ parameters.productionGit }}', ''), ne('${{ parameters.productionBranch }}', ''))
  displayName: "Push to WPEngine Prod"
  inputs:
    targetType: 'inline'
    script: |
      git config --global user.email "${{ parameters.gitEmail }}"
      git config --global user.name "${{ parameters.gitUser }}"
      git checkout ${{ parameters.productionBranch }}
      find . -name ".gitignore" -exec rm -f {} \;
      git add .
      git commit -m "Push to WPEngine"
      git push -f ${{ parameters.productionGit }} ${{ parameters.productionBranch }}
    
- task: [email protected]
  condition: and(eq(variables['build.sourceBranch'], 'refs/heads/${{ parameters.stagingBranch }}'), ne('${{ parameters.stagingGit }}', ''), ne('${{ parameters.stagingBranch }}', ''))
  displayName: "Push to WPEngine Staging"
  inputs:
    targetType: 'inline'
    script: |
      git config --global user.email "${{ parameters.gitEmail }}"
      git config --global user.name "${{ parameters.gitUser }}"
      git checkout ${{ parameters.stagingBranch }}
      find . -name ".gitignore" -exec rm -f {} \;
      git add .
      git commit -m "Push to WPEngine"
      git push -f ${{ parameters.stagingGit }} ${{ parameters.stagingBranch }}
      
- task: [email protected]
  condition: and(eq(variables['build.sourceBranch'], 'refs/heads/${{ parameters.developmentBranch }}'), ne('${{ parameters.developmentGit }}', ''), ne('${{ parameters.developmentBranch }}', ''))
  displayName: "Push to WPEngine Development"
  inputs:
    targetType: 'inline'
    script: |
      git config --global user.email "${{ parameters.gitEmail }}"
      git config --global user.name "${{ parameters.gitUser }}"
      git checkout ${{ parameters.developmentBranch }}
      find . -name ".gitignore" -exec rm -f {} \;
      git add .
      git commit -m "Push to WPEngine"
      git push -f ${{ parameters.developmentGit }} ${{ parameters.developmentBranch }}
  1. This file shouldn’t need any changes unless there are any default values you would like to carry over between sites.
  2. Commit both files

Add SSH Key to Azure DevOps

  1. Open your project in Azure DevOps
  2. Open Pipelines in the left menu
  3. Open the library section under Pipelines
  4. Click on Secure files in the tab on the top
  5. Click the + to add a new file
  6. Upload your private key as id_rsa_azure
  7. Click on Variable Groups at the top
  8. Create a new variable group
  9. Name the variable group ssh-info
  10. Add an entry for knownHostsEntry and add the host entry for WP Engine
    • You can find this by running ssh [email protected] info from the local computer where your key was installed, and copying the host entry from ~/.ssh/known_hosts
  11. Add an entry for sshPublicKey with the value from the public key you added to WP Engine

Create a Pipeline

  1. Go to the Azure Devops Project
  2. Open Pipelines on the left Menu
  3. Click New Pipeline
  4. Select Azure Repos Git
  5. Select your repository
  6. Select Existing Azure Pipelines YAML File
  7. Select the branch you have the .yml files committed to
  8. Select azure-pipelines.yml
  9. Select the dropdown next to “Run” and click save

At this point the pipeline will be created, but not yet running.


Run Your Pipeline

Your pipeline can now be run manually or will automatically run when a branch is pushed to.

Manually

  1. Open your project
  2. Click on the Pipelines
  3. Select the pipeline you’d like to run
  4. Click the Run Pipeline in the menu
  5. Select the Branch you’d like to run the pipeline on
  6. Click Run

Automatically

Push to any of the branches under “trigger” in the template and Azure DevOps will recognize it and automatically run the pipeline for you.

This lets you use continuous integration as well as utilize other CI/CD tools inside the pipeline.


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

Still need help? Contact support!

We offer support 24 hours a day, 7 days a week, 365 days a year. Log in to your account to get expert one-on-one help.

The best in WordPress hosting.

See why more customers prefer WP Engine over the competition.