Deploy a PR environment

New! Automatic deployments to a pull request now available. Configured by adding:

auto_deploy_on: pr

Deploying our code in a pull request is a great way of quickly giving developers or designers an easy way of seeing their changes live before they merge them into master and deploy them to production.

Here we are going to create a review target which will deploy to a dynamic environment name using a PR number. Previously we used static environment names the dynamic environment name should trigger our deployment automation to spin up a new environment and deploy our code to this.

# .github/deploy.yml
  # Set the transient environment flag to let GitHub and Deliverybot know that
  # this environment should be destroyed when the PR is closed.
  transient_environment: true
  production_environment: false

  # Dynamic environment name. The environment will look like pr123.
  environment: pr${{ pr }}

Using this we can then trigger a deployment inside a pull request by typing the below command into the pull request comments.

/deploy review

Or, optionally, to trigger automatic deploys when a pull request is opened or synchronized you can add the following to the configuration file:

# .github/deploy.yml
  transient_environment: true
  production_environment: false
  environment: pr${{ pr }}
  auto_deploy_on: pr

An example of what a pr environment deploy looks like:

Deploy on pr environments


One thing we’ll also want to include at this point is configuration to delete our dynamic pull request environment when the pull request is closed. We listen for the closed pull request event in GitHub actions and trigger code to remove this environment.

Copy the below file into .github/workflows/pr-cleanup.yml to setup this workflow.

# .github/workflows/pr-cleanup.yml
name: PRCleanup
    types: [closed]

    runs-on: 'ubuntu-latest'
    - name: 'remove'
      run: |
        echo 'remove pr${{ github.event.pull_request.number }}'

Compatible integrations

Follow the guides in these integrations below for implementing pull request deployments.


Promote a commit »

Need help?
Or chat with the community on Spectrum